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

Commitbe6bc28

Browse files
committed
Add completions for env names to be enabled later
1 parent74a130a commitbe6bc28

File tree

6 files changed

+64
-26
lines changed

6 files changed

+64
-26
lines changed

‎ci/integration/setup_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"golang.org/x/xerrors"
1414
)
1515

16+
// binpath is populated during package initialization with a path to the coder binary
1617
varbinpathstring
1718

1819
// initialize integration tests by building the coder-cli binary

‎cmd/coder/auth.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,38 @@ import (
55

66
"cdr.dev/coder-cli/internal/config"
77
"cdr.dev/coder-cli/internal/entclient"
8+
"golang.org/x/xerrors"
89

910
"go.coder.com/flog"
1011
)
1112

1213
// requireAuth exits the process with a nonzero exit code if the user is not authenticated to make requests
1314
funcrequireAuth()*entclient.Client {
15+
client,err:=newClient()
16+
iferr!=nil {
17+
flog.Fatal("%v",err)
18+
}
19+
returnclient
20+
}
21+
22+
funcnewClient() (*entclient.Client,error) {
1423
sessionToken,err:=config.Session.Read()
15-
requireSuccess(err,"read session: %v (did you run coder login?)",err)
24+
iferr!=nil {
25+
returnnil,xerrors.Errorf("read session: %v (did you run coder login?)",err)
26+
}
1627

1728
rawURL,err:=config.URL.Read()
18-
requireSuccess(err,"read url: %v (did you run coder login?)",err)
29+
iferr!=nil {
30+
returnnil,xerrors.Errorf("read url: %v (did you run coder login?)",err)
31+
}
1932

2033
u,err:=url.Parse(rawURL)
21-
requireSuccess(err,"url misformatted: %v (try runing coder login)",err)
34+
iferr!=nil {
35+
returnnil,xerrors.Errorf("url misformatted: %v (try runing coder login)",err)
36+
}
2237

2338
return&entclient.Client{
2439
BaseURL:u,
2540
Token:sessionToken,
26-
}
27-
}
28-
29-
// requireSuccess prints the given message and format args as a fatal error if err != nil
30-
funcrequireSuccess(errerror,msgstring,args...interface{}) {
31-
iferr!=nil {
32-
flog.Fatal(msg,args...)
33-
}
41+
},nil
3442
}

‎cmd/coder/secrets.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ func makeSecretsCmd() *cobra.Command {
2828
},
2929
makeCreateSecret(),
3030
&cobra.Command{
31-
Use:"rm [...secret_name]",
32-
Short:"Remove one or more secrets by name",
33-
Args:cobra.MinimumNArgs(1),
34-
RunE:removeSecrets,
31+
Use:"rm [...secret_name]",
32+
Short:"Remove one or more secrets by name",
33+
Args:cobra.MinimumNArgs(1),
34+
RunE:removeSecrets,
35+
Example:"coder secrets rm mysql-password mysql-user",
3536
},
3637
&cobra.Command{
37-
Use:"view [secret_name]",
38-
Short:"View a secret by name",
39-
Args:cobra.ExactArgs(1),
40-
RunE:viewSecret,
38+
Use:"view [secret_name]",
39+
Short:"View a secret by name",
40+
Args:cobra.ExactArgs(1),
41+
RunE:viewSecret,
42+
Example:"coder secrets view mysql-password",
4143
},
4244
)
4345
returncmd
@@ -55,6 +57,9 @@ func makeCreateSecret() *cobra.Command {
5557
Use:"create [secret_name]",
5658
Short:"Create a new secret",
5759
Long:"Create a new secret object to store application secrets and access them securely from within your environments.",
60+
Example:`coder secrets create mysql-password --from-literal 123password
61+
coder secrets create mysql-password --from-prompt
62+
coder secrets create aws-credentials --from-file ./credentials.json`,
5863
Args:func(cmd*cobra.Command,args []string)error {
5964
iflen(args)<1 {
6065
returnxerrors.Errorf("[secret_name] is a required argument")

‎cmd/coder/shell.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,39 @@ import (
1919
"go.coder.com/flog"
2020
)
2121

22+
funcgetEnvsForCompletion() []string {
23+
// TODO(@cmoog): Enable this if speed issue can be resolved. Otherwise, all commands will take > 1 second.
24+
returnnil
25+
26+
varenvNames []string
27+
client,err:=newClient()
28+
iferr!=nil {
29+
returnenvNames
30+
}
31+
envs,err:=getEnvs(client)
32+
iferr!=nil {
33+
returnenvNames
34+
}
35+
for_,e:=rangeenvs {
36+
envNames=append(envNames,e.Name)
37+
}
38+
returnenvNames
39+
}
40+
2241
funcmakeShellCmd()*cobra.Command {
2342
return&cobra.Command{
2443
Use:"sh [environment_name] [<command [args...]>]",
2544
Short:"Open a shell and execute commands in a Coder environment",
2645
Long:"Execute a remote command on the environment\\nIf no command is specified, the default shell is opened.",
2746
Args:cobra.MinimumNArgs(1),
2847
DisableFlagParsing:true,
48+
ValidArgs:getEnvsForCompletion(),
2949
RunE:shell,
50+
Example:"coder sh backend-env",
3051
}
3152
}
3253

33-
funcshell(cmd*cobra.Command,cmdArgs []string)error {
54+
funcshell(_*cobra.Command,cmdArgs []string)error {
3455
var (
3556
envName=cmdArgs[0]
3657
ctx=context.Background()

‎cmd/coder/urls.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ func makeURLCmd() *cobra.Command {
2323
Short:"Interact with environment DevURLs",
2424
}
2525
lsCmd:=&cobra.Command{
26-
Use:"ls [env_name]",
27-
Short:"List all DevURLs for an environment",
28-
Args:cobra.ExactArgs(1),
29-
RunE:makeListDevURLs(&outputFmt),
26+
Use:"ls [environment_name]",
27+
Short:"List all DevURLs for an environment",
28+
Args:cobra.ExactArgs(1),
29+
ValidArgs:getEnvsForCompletion(),
30+
RunE:makeListDevURLs(&outputFmt),
3031
}
3132
lsCmd.Flags().StringVarP(&outputFmt,"output","o","human","human|json")
3233

‎cmd/coder/users.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ func makeUsersCmd() *cobra.Command {
1919
lsCmd:=&cobra.Command{
2020
Use:"ls",
2121
Short:"list all user accounts",
22-
RunE:listUsers(&outputFmt),
22+
Example:`coder users ls -o json
23+
coder users ls -o json | jq .[] | jq -r .email`,
24+
RunE:listUsers(&outputFmt),
2325
}
24-
lsCmd.Flags().StringVarP(&outputFmt,"output","0","human","human | json")
26+
lsCmd.Flags().StringVarP(&outputFmt,"output","o","human","human | json")
2527

2628
cmd.AddCommand(lsCmd)
2729
returncmd

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp