Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit9b61d34

Browse files
committed
Move cmd to internal package
1 parente3efdad commit9b61d34

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
deferxterminal.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
iferr!=nil {
5843
os.Exit(1)
5944
}
6045
}
61-
62-
// reference: https://github.com/spf13/cobra/blob/master/shell_completions.md
63-
varcompletionCmd=&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-
switchargs[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.gorenamed to‎internal/cmd/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"net/url"

‎cmd/coder/ceapi.gorenamed to‎internal/cmd/ceapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
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+
funcMake()*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+
returnapp
28+
}
29+
30+
// reference: https://github.com/spf13/cobra/blob/master/shell_completions.md
31+
varcompletionCmd=&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+
switchargs[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.gorenamed to‎internal/cmd/configssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"context"

‎cmd/coder/envs.gorenamed to‎internal/cmd/envs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"encoding/json"

‎cmd/coder/login.gorenamed to‎internal/cmd/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"net"

‎cmd/coder/logout.gorenamed to‎internal/cmd/logout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"os"

‎cmd/coder/secrets.gorenamed to‎internal/cmd/secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"fmt"

‎cmd/coder/shell.gorenamed to‎internal/cmd/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"context"

‎cmd/coder/sync.gorenamed to‎internal/cmd/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"bytes"

‎cmd/coder/urls.gorenamed to‎internal/cmd/urls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"context"

‎cmd/coder/users.gorenamed to‎internal/cmd/users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
packagemain
1+
packagecmd
22

33
import (
44
"encoding/json"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp