Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 9b61d34

Browse files
committed
Move cmd to internal package
1 parent e3efdad commit 9b61d34

File tree

13 files changed

+94
-81
lines changed

13 files changed

+94
-81
lines changed

Diff for: cmd/coder/main.go

+3-70
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"os"
1010
"runtime"
1111

12+
"cdr.dev/coder-cli/internal/cmd"
1213
"cdr.dev/coder-cli/internal/x/xterminal"
13-
"github.com/spf13/cobra"
1414

1515
"go.coder.com/flog"
1616
)
@@ -35,78 +35,11 @@ func main() {
3535
}
3636
defer xterminal.Restore(os.Stdout.Fd(), stdoutState)
3737

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)
4340

44-
app.AddCommand(
45-
makeLoginCmd(),
46-
makeLogoutCmd(),
47-
makeShellCmd(),
48-
makeUsersCmd(),
49-
makeConfigSSHCmd(),
50-
makeSecretsCmd(),
51-
makeEnvsCommand(),
52-
makeSyncCmd(),
53-
makeURLCmd(),
54-
completionCmd,
55-
)
5641
err = app.ExecuteContext(ctx)
5742
if err != nil {
5843
os.Exit(1)
5944
}
6045
}
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-
}

Diff for: cmd/coder/auth.go renamed to internal/cmd/auth.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"net/url"

Diff for: cmd/coder/ceapi.go renamed to internal/cmd/ceapi.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"context"

Diff for: internal/cmd/cmd.go

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func Make() *cobra.Command {
10+
app := &cobra.Command{
11+
Use: "coder",
12+
Short: "coder provides a CLI for working with an existing Coder Enterprise installation",
13+
}
14+
15+
app.AddCommand(
16+
makeLoginCmd(),
17+
makeLogoutCmd(),
18+
makeShellCmd(),
19+
makeUsersCmd(),
20+
makeConfigSSHCmd(),
21+
makeSecretsCmd(),
22+
makeEnvsCommand(),
23+
makeSyncCmd(),
24+
makeURLCmd(),
25+
completionCmd,
26+
)
27+
return app
28+
}
29+
30+
// reference: https://github.com/spf13/cobra/blob/master/shell_completions.md
31+
var completionCmd = &cobra.Command{
32+
Use: "completion [bash|zsh|fish|powershell]",
33+
Short: "Generate completion script",
34+
Long: `To load completions:
35+
36+
Bash:
37+
38+
$ source <(coder completion bash)
39+
40+
# To load completions for each session, execute once:
41+
Linux:
42+
$ coder completion bash > /etc/bash_completion.d/coder
43+
MacOS:
44+
$ coder completion bash > /usr/local/etc/bash_completion.d/coder
45+
46+
Zsh:
47+
48+
# If shell completion is not already enabled in your environment you will need
49+
# to enable it. You can execute the following once:
50+
51+
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
52+
53+
# To load completions for each session, execute once:
54+
$ coder completion zsh > "${fpath[1]}/_coder"
55+
56+
# You will need to start a new shell for this setup to take effect.
57+
58+
Fish:
59+
60+
$ coder completion fish | source
61+
62+
# To load completions for each session, execute once:
63+
$ coder completion fish > ~/.config/fish/completions/coder.fish
64+
`,
65+
DisableFlagsInUseLine: true,
66+
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
67+
Args: cobra.ExactValidArgs(1),
68+
Run: func(cmd *cobra.Command, args []string) {
69+
switch args[0] {
70+
case "bash":
71+
cmd.Root().GenBashCompletion(os.Stdout)
72+
case "zsh":
73+
cmd.Root().GenZshCompletion(os.Stdout)
74+
case "fish":
75+
cmd.Root().GenFishCompletion(os.Stdout, true)
76+
case "powershell":
77+
cmd.Root().GenPowerShellCompletion(os.Stdout)
78+
}
79+
},
80+
}

Diff for: cmd/coder/configssh.go renamed to internal/cmd/configssh.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"context"

Diff for: cmd/coder/envs.go renamed to internal/cmd/envs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"encoding/json"

Diff for: cmd/coder/login.go renamed to internal/cmd/login.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"net"

Diff for: cmd/coder/logout.go renamed to internal/cmd/logout.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"os"

Diff for: cmd/coder/secrets.go renamed to internal/cmd/secrets.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"fmt"

Diff for: cmd/coder/shell.go renamed to internal/cmd/shell.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"context"

Diff for: cmd/coder/sync.go renamed to internal/cmd/sync.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"bytes"

Diff for: cmd/coder/urls.go renamed to internal/cmd/urls.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"context"

Diff for: cmd/coder/users.go renamed to internal/cmd/users.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"encoding/json"

0 commit comments

Comments
 (0)