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

Commit4752bfc

Browse files
committed
Add completions for env names
1 parentaa300a2 commit4752bfc

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

‎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/shell.go

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

22+
funcgetEnvsForCompletion() []string {
23+
varenvNames []string
24+
client,err:=newClient()
25+
iferr!=nil {
26+
returnenvNames
27+
}
28+
envs,err:=getEnvs(client)
29+
iferr!=nil {
30+
returnenvNames
31+
}
32+
for_,e:=rangeenvs {
33+
envNames=append(envNames,e.Name)
34+
}
35+
returnenvNames
36+
}
37+
2238
funcmakeShellCmd()*cobra.Command {
2339
return&cobra.Command{
2440
Use:"sh [environment_name] [<command [args...]>]",
2541
Short:"Open a shell and execute commands in a Coder environment",
2642
Long:"Execute a remote command on the environment\\nIf no command is specified, the default shell is opened.",
2743
Args:cobra.MinimumNArgs(1),
2844
DisableFlagParsing:true,
45+
ValidArgs:getEnvsForCompletion(),
2946
RunE:shell,
3047
}
3148
}
3249

33-
funcshell(cmd*cobra.Command,cmdArgs []string)error {
50+
funcshell(_*cobra.Command,cmdArgs []string)error {
3451
var (
3552
envName=cmdArgs[0]
3653
ctx=context.Background()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp