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

Commit1780192

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

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

‎docs/coder_envs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Perform operations on the Coder environments owned by the active user.
2323

2424
*[coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
2525
*[coder envs ls](coder_envs_ls.md) - list all environments owned by the active user
26-
*[coder envs stop](coder_envs_stop.md) - stopaCoderenvironment by name
26+
*[coder envs stop](coder_envs_stop.md) - stop Coderenvironments by name

‎docs/coder_envs_stop.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
##coder envs stop
22

3-
stopaCoderenvironment by name
3+
stop Coderenvironments by name
44

55
###Synopsis
66

7-
StopaCoderenvironment by name
7+
Stop Coderenvironments by name
88

99
```
10-
coder envs stop [environment_name] [flags]
10+
coder envs stop [...environment_names] [flags]
11+
```
12+
13+
###Examples
14+
15+
```
16+
coder envs stop front-end-env
17+
coder envs stop front-end-env backend-env
18+
19+
# stop all of your environments
20+
coder envs ls -o json | jq -c '.[].name' | xargs coder envs stop
21+
22+
# stop all environments for a given user
23+
coder envs --user charlie@coder.com ls -o json \
24+
| jq -c '.[].name' \
25+
| xargs coder envs --user charlie@coder.com stop
1126
```
1227

1328
###Options

‎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: 34 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,47 @@ 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+
# stop all of your environments
79+
coder envs ls -o json | jq -c '.[].name' | xargs coder envs stop
80+
81+
# stop all environments for a given user
82+
coder envs --user charlie@coder.com ls -o json \
83+
| jq -c '.[].name' \
84+
| xargs coder envs --user charlie@coder.com stop`,
85+
Args:cobra.MinimumNArgs(1),
7586
RunE:func(cmd*cobra.Command,args []string)error {
7687
client,err:=newClient()
7788
iferr!=nil {
7889
returnxerrors.Errorf("new client: %w",err)
7990
}
8091

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)
92+
varegroup errgroup.Group
93+
for_,envName:=rangeargs {
94+
envName:=envName
95+
egroup.Go(func()error {
96+
env,err:=findEnv(cmd.Context(),client,envName,*user)
97+
iferr!=nil {
98+
returnxerrors.Errorf("find environment by name: %w",err)
99+
}
100+
101+
iferr=client.StopEnvironment(cmd.Context(),env.ID);err!=nil {
102+
flog.Error("failed to stop environment\"%s\": %v",env.Name,err)
103+
returnxerrors.Errorf("stop environment: %w",err)
104+
}
105+
flog.Success("Successfully stopped environment %q",envName)
106+
returnnil
107+
})
85108
}
86109

87-
iferr=client.StopEnvironment(cmd.Context(),env.ID);err!=nil {
88-
returnxerrors.Errorf("stopenvironment: %w",err)
110+
iferr=egroup.Wait();err!=nil {
111+
returnxerrors.Errorf("somestopoperations failed: %w",err)
89112
}
90-
flog.Success("Successfully stopped environment %q",envName)
91113
returnnil
92114
},
93115
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp