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

cmd/coder/main.go

Lines changed: 3 additions & 70 deletions
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-
}

cmd/coder/auth.go renamed to internal/cmd/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"net/url"

cmd/coder/ceapi.go renamed to internal/cmd/ceapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"context"

internal/cmd/cmd.go

Lines changed: 80 additions & 0 deletions
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+
}

cmd/coder/configssh.go renamed to internal/cmd/configssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"context"

cmd/coder/envs.go renamed to internal/cmd/envs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"encoding/json"

cmd/coder/login.go renamed to internal/cmd/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"net"

cmd/coder/logout.go renamed to internal/cmd/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"os"

cmd/coder/secrets.go renamed to internal/cmd/secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"fmt"

cmd/coder/shell.go renamed to internal/cmd/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cmd
22

33
import (
44
"context"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy