9
9
"os"
10
10
"runtime"
11
11
12
+ "cdr.dev/coder-cli/internal/cmd"
12
13
"cdr.dev/coder-cli/internal/x/xterminal"
13
- "github.com/spf13/cobra"
14
14
15
15
"go.coder.com/flog"
16
16
)
@@ -35,78 +35,11 @@ func main() {
35
35
}
36
36
defer xterminal .Restore (os .Stdout .Fd (), stdoutState )
37
37
38
- app := & cobra.Command {
39
- Use : "coder" ,
40
- Short : "coder provides a CLI for working with an existing Coder Enterprise installation" ,
41
- Version : fmt .Sprintf ("%s %s %s/%s" , version , runtime .Version (), runtime .GOOS , runtime .GOARCH ),
42
- }
38
+ app := cmd .Make ()
39
+ app .Version = fmt .Sprintf ("%s %s %s/%s" , version , runtime .Version (), runtime .GOOS , runtime .GOARCH )
43
40
44
- app .AddCommand (
45
- makeLoginCmd (),
46
- makeLogoutCmd (),
47
- makeShellCmd (),
48
- makeUsersCmd (),
49
- makeConfigSSHCmd (),
50
- makeSecretsCmd (),
51
- makeEnvsCommand (),
52
- makeSyncCmd (),
53
- makeURLCmd (),
54
- completionCmd ,
55
- )
56
41
err = app .ExecuteContext (ctx )
57
42
if err != nil {
58
43
os .Exit (1 )
59
44
}
60
45
}
61
-
62
- // reference: https://github.com/spf13/cobra/blob/master/shell_completions.md
63
- var completionCmd = & cobra.Command {
64
- Use : "completion [bash|zsh|fish|powershell]" ,
65
- Short : "Generate completion script" ,
66
- Long : `To load completions:
67
-
68
- Bash:
69
-
70
- $ source <(yourprogram completion bash)
71
-
72
- # To load completions for each session, execute once:
73
- Linux:
74
- $ yourprogram completion bash > /etc/bash_completion.d/yourprogram
75
- MacOS:
76
- $ yourprogram completion bash > /usr/local/etc/bash_completion.d/yourprogram
77
-
78
- Zsh:
79
-
80
- # If shell completion is not already enabled in your environment you will need
81
- # to enable it. You can execute the following once:
82
-
83
- $ echo "autoload -U compinit; compinit" >> ~/.zshrc
84
-
85
- # To load completions for each session, execute once:
86
- $ yourprogram completion zsh > "${fpath[1]}/_yourprogram"
87
-
88
- # You will need to start a new shell for this setup to take effect.
89
-
90
- Fish:
91
-
92
- $ yourprogram completion fish | source
93
-
94
- # To load completions for each session, execute once:
95
- $ yourprogram completion fish > ~/.config/fish/completions/yourprogram.fish
96
- ` ,
97
- DisableFlagsInUseLine : true ,
98
- ValidArgs : []string {"bash" , "zsh" , "fish" , "powershell" },
99
- Args : cobra .ExactValidArgs (1 ),
100
- Run : func (cmd * cobra.Command , args []string ) {
101
- switch args [0 ] {
102
- case "bash" :
103
- cmd .Root ().GenBashCompletion (os .Stdout )
104
- case "zsh" :
105
- cmd .Root ().GenZshCompletion (os .Stdout )
106
- case "fish" :
107
- cmd .Root ().GenFishCompletion (os .Stdout , true )
108
- case "powershell" :
109
- cmd .Root ().GenPowerShellCompletion (os .Stdout )
110
- }
111
- },
112
- }
0 commit comments