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

Allow multiple env args to env stop command#144

Merged
cmoog merged 2 commits intomasterfromstop-many
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletiondocs/coder_envs.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,4 +23,4 @@ Perform operations on the Coder environments owned by the active user.

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
* [coder envs ls](coder_envs_ls.md) - list all environments owned by the active user
* [coder envs stop](coder_envs_stop.md) - stopaCoderenvironment by name
* [coder envs stop](coder_envs_stop.md) - stop Coderenvironments by name
21 changes: 18 additions & 3 deletionsdocs/coder_envs_stop.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
## coder envs stop

stopaCoderenvironment by name
stop Coderenvironments by name

### Synopsis

StopaCoderenvironment by name
Stop Coderenvironments by name

```
coder envs stop [environment_name] [flags]
coder envs stop [...environment_names] [flags]
```

### Examples

```
coder envs stop front-end-env
coder envs stop front-end-env backend-env

# stop all of your environments
coder envs ls -o json | jq -c '.[].name' | xargs coder envs stop

# stop all environments for a given user
coder envs --user charlie@coder.com ls -o json \
| jq -c '.[].name' \
| xargs coder envs --user charlie@coder.com stop
```

### Options
Expand Down
2 changes: 1 addition & 1 deletioninternal/cmd/cmd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,7 +24,7 @@ func Make() *cobra.Command {
makeUsersCmd(),
makeConfigSSHCmd(),
makeSecretsCmd(),
makeEnvsCommand(),
envsCommand(),
makeSyncCmd(),
makeURLCmd(),
makeResourceCmd(),
Expand Down
47 changes: 35 additions & 12 deletionsinternal/cmd/envs.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,12 +7,13 @@ import (
"cdr.dev/coder-cli/coder-sdk"
"cdr.dev/coder-cli/internal/x/xtabwriter"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
"golang.org/x/xerrors"

"go.coder.com/flog"
)

funcmakeEnvsCommand() *cobra.Command {
funcenvsCommand() *cobra.Command {
var outputFmt string
var user string
cmd := &cobra.Command{
Expand DownExpand Up@@ -68,26 +69,48 @@ func makeEnvsCommand() *cobra.Command {

func stopEnvCommand(user *string) *cobra.Command {
return &cobra.Command{
Use: "stop [environment_name]",
Short: "stop a Coder environment by name",
Long: "Stop a Coder environment by name",
Args: cobra.ExactArgs(1),
Use: "stop [...environment_names]",
Short: "stop Coder environments by name",
Long: "Stop Coder environments by name",
Example: `coder envs stop front-end-env
coder envs stop front-end-env backend-env

# stop all of your environments
coder envs ls -o json | jq -c '.[].name' | xargs coder envs stop

# stop all environments for a given user
coder envs --user charlie@coder.com ls -o json \
| jq -c '.[].name' \
| xargs coder envs --user charlie@coder.com stop`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := newClient()
if err != nil {
return xerrors.Errorf("new client: %w", err)
}

envName := args[0]
env, err := findEnv(cmd.Context(), client, envName, *user)
if err != nil {
return xerrors.Errorf("find environment by name: %w", err)
var egroup errgroup.Group
for _, envName := range args {
envName := envName
egroup.Go(func() error {
env, err := findEnv(cmd.Context(), client, envName, *user)
if err != nil {
flog.Error("failed to find environment by name \"%s\": %v", env.Name, err)
return xerrors.Errorf("find environment by name: %w", err)
}

if err = client.StopEnvironment(cmd.Context(), env.ID); err != nil {
flog.Error("failed to stop environment \"%s\": %v", env.Name, err)
return xerrors.Errorf("stop environment: %w", err)
}
flog.Success("Successfully stopped environment %q", envName)
return nil
})
}

if err =client.StopEnvironment(cmd.Context(), env.ID); err != nil {
return xerrors.Errorf("stopenvironment: %w", err)
if err =egroup.Wait(); err != nil {
return xerrors.Errorf("somestopoperations failed: %w", err)
}
flog.Success("Successfully stopped environment %q", envName)
return nil
},
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp