@@ -8,32 +8,38 @@ import (
88 "github.com/spf13/cobra"
99)
1010
11- func switchCommand () * cobra.Command {
12- cmd := & cobra.Command {
13- Use : "switch [organization]" ,
14- Short : "Switch between organizations" ,
15- Long : `Switch between Dispatch organizations.
11+ var (
12+ SwitchCmdLong = `Switch between Dispatch organizations.
1613
1714The switch command is used to select which organization is used
1815when running a Dispatch application locally.
16+
17+ To manage your organizations, visit the Dispatch Console: https://console.dispatch.run/`
18+ )
1919
20- To manage your organizations, visit the Dispatch Console: https://console.dispatch.run/` ,
20+ func switchCommand (configPath string ) * cobra.Command {
21+ cmd := & cobra.Command {
22+ Use : "switch [organization]" ,
23+ Short : "Switch between organizations" ,
24+ Long : SwitchCmdLong ,
2125 GroupID : "management" ,
2226 RunE : func (cmd * cobra.Command , args []string ) error {
23- cfg , err := LoadConfig (DispatchConfigPath )
27+ cfg , err := LoadConfig (configPath )
2428 if err != nil {
2529 if ! errors .Is (err , os .ErrNotExist ) {
26- failure (fmt .Sprintf ("Failed to load Dispatch configuration: %v" , err ))
30+ failure (cmd , fmt .Sprintf ("Failed to load Dispatch configuration: %v" , err ))
2731 }
28- simple ("Please run `dispatch login` to login to Dispatch." )
32+
33+ // User must login to create a configuration file.
34+ simple (cmd , "Please run `dispatch login` to login to Dispatch." )
2935 return nil
3036 }
3137
3238 // List organizations if no arguments were provided.
3339 if len (args ) == 0 {
34- fmt . Println ( "Available organizations:" )
40+ simple ( cmd , "Available organizations:" )
3541 for org := range cfg .Organization {
36- fmt . Println ( "-" , org )
42+ simple ( cmd , "-" , org )
3743 }
3844 return nil
3945 }
@@ -42,18 +48,18 @@ To manage your organizations, visit the Dispatch Console: https://console.dispat
4248 name := args [0 ]
4349 _ , ok := cfg .Organization [name ]
4450 if ! ok {
45- failure (fmt .Sprintf ("Organization '%s' not found" , name ))
51+ failure (cmd , fmt .Sprintf ("Organization '%s' not found" , name ))
4652
47- fmt . Println ( "Available organizations:" )
53+ simple ( cmd , "Available organizations:" )
4854 for org := range cfg .Organization {
49- fmt . Println ( "-" , org )
55+ simple ( cmd , "-" , org )
5056 }
5157 return nil
5258 }
5359
54- simple (fmt .Sprintf ("Switched to organization: %v" , name ))
60+ simple (cmd , fmt .Sprintf ("Switched to organization: %v" , name ))
5561 cfg .Active = name
56- return CreateConfig (DispatchConfigPath , cfg )
62+ return CreateConfig (configPath , cfg )
5763 },
5864 }
5965 return cmd
0 commit comments