Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Stop cmd #136

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions coder-sdk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func (c Client) DeleteEnvironment(ctx context.Context, envID string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/environments/"+envID, nil, nil)
}

// StopEnvironment stops the stops.
func (c Client) StopEnvironment(ctx context.Context, envID string) error {
return c.requestBody(ctx, http.MethodPut, "/api/environments/"+envID+"/stop", nil, nil)
}

// DialWsep dials an environments command execution interface
// See https://github.com/cdr/wsep for details.
func (c Client) DialWsep(ctx context.Context, env *Environment) (*websocket.Conn, error) {
Expand Down
1 change: 1 addition & 0 deletions docs/coder_envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,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) - stop a Coder environment by name
27 changes: 27 additions & 0 deletions docs/coder_envs_stop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## coder envs stop

stop a Coder environment by name

### Synopsis

Stop a Coder environment by name

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

### Options

```
-h, --help help for stop
```

### Options inherited from parent commands

```
--user string Specify the user whose resources to target (default "me")
```

### SEE ALSO

* [coder envs](coder_envs.md) - Interact with Coder environments
28 changes: 28 additions & 0 deletions internal/cmd/envs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ func makeEnvsCommand() *cobra.Command {
}
lsCmd.Flags().StringVarP(&outputFmt, "output", "o", "human", "human | json")
cmd.AddCommand(lsCmd)
cmd.AddCommand(stopEnvCommand(&user))

return cmd
}

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),
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)
}

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