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

Commitb3a3807

Browse files
committed
Allow multiple env args to env stop command
1 parente5d55d0 commitb3a3807

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

‎internal/cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Make() *cobra.Command {
2424
makeUsersCmd(),
2525
makeConfigSSHCmd(),
2626
makeSecretsCmd(),
27-
makeEnvsCommand(),
27+
envsCommand(),
2828
makeSyncCmd(),
2929
makeURLCmd(),
3030
makeResourceCmd(),

‎internal/cmd/envs.go

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
"cdr.dev/coder-cli/coder-sdk"
88
"cdr.dev/coder-cli/internal/x/xtabwriter"
99
"github.com/spf13/cobra"
10+
"golang.org/x/sync/errgroup"
1011
"golang.org/x/xerrors"
1112

1213
"go.coder.com/flog"
1314
)
1415

15-
funcmakeEnvsCommand()*cobra.Command {
16+
funcenvsCommand()*cobra.Command {
1617
varoutputFmtstring
1718
varuserstring
1819
cmd:=&cobra.Command{
@@ -68,26 +69,43 @@ func makeEnvsCommand() *cobra.Command {
6869

6970
funcstopEnvCommand(user*string)*cobra.Command {
7071
return&cobra.Command{
71-
Use:"stop [environment_name]",
72-
Short:"stop a Coder environment by name",
73-
Long:"Stop a Coder environment by name",
74-
Args:cobra.ExactArgs(1),
72+
Use:"stop [...environment_names]",
73+
Short:"stop Coder environments by name",
74+
Long:"Stop Coder environments by name",
75+
Example:`coder envs stop front-end-env
76+
coder envs stop front-end-env backend-env
77+
78+
# to stop all of your environments:
79+
coder envs ls -o json | jq -c '.[].name' | xargs coder envs stop
80+
`,
81+
Args:cobra.MinimumNArgs(1),
7582
RunE:func(cmd*cobra.Command,args []string)error {
7683
client,err:=newClient()
7784
iferr!=nil {
7885
returnxerrors.Errorf("new client: %w",err)
7986
}
8087

81-
envName:=args[0]
82-
env,err:=findEnv(cmd.Context(),client,envName,*user)
83-
iferr!=nil {
84-
returnxerrors.Errorf("find environment by name: %w",err)
88+
varegroup errgroup.Group
89+
for_,envName:=rangeargs {
90+
envName:=envName
91+
egroup.Go(func()error {
92+
env,err:=findEnv(cmd.Context(),client,envName,*user)
93+
iferr!=nil {
94+
returnxerrors.Errorf("find environment by name: %w",err)
95+
}
96+
97+
iferr=client.StopEnvironment(cmd.Context(),env.ID);err!=nil {
98+
flog.Error("failed to stop environment\"%s\": %v",env.Name,err)
99+
returnxerrors.Errorf("stop environment: %w",err)
100+
}
101+
flog.Success("Successfully stopped environment %q",envName)
102+
returnnil
103+
})
85104
}
86105

87-
iferr=client.StopEnvironment(cmd.Context(),env.ID);err!=nil {
88-
returnxerrors.Errorf("stopenvironment: %w",err)
106+
iferr=egroup.Wait();err!=nil {
107+
returnxerrors.Errorf("somestopoperations failed: %w",err)
89108
}
90-
flog.Success("Successfully stopped environment %q",envName)
91109
returnnil
92110
},
93111
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp