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

Commit d765c36

Browse files
authored
Add "coder envs stop [environment_name]" command (#136)
1 parent b7cd44f commit d765c36

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

Diff for: coder-sdk/env.go

+5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ func (c Client) DeleteEnvironment(ctx context.Context, envID string) error {
107107
return c.requestBody(ctx, http.MethodDelete, "/api/environments/"+envID, nil, nil)
108108
}
109109

110+
// StopEnvironment stops the stops.
111+
func (c Client) StopEnvironment(ctx context.Context, envID string) error {
112+
return c.requestBody(ctx, http.MethodPut, "/api/environments/"+envID+"/stop", nil, nil)
113+
}
114+
110115
// DialWsep dials an environments command execution interface
111116
// See https://github.com/cdr/wsep for details.
112117
func (c Client) DialWsep(ctx context.Context, env *Environment) (*websocket.Conn, error) {

Diff for: docs/coder_envs.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Perform operations on the Coder environments owned by the active user.
1717

1818
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
1919
* [coder envs ls](coder_envs_ls.md) - list all environments owned by the active user
20+
* [coder envs stop](coder_envs_stop.md) - stop a Coder environment by name

Diff for: docs/coder_envs_stop.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## coder envs stop
2+
3+
stop a Coder environment by name
4+
5+
### Synopsis
6+
7+
Stop a Coder environment by name
8+
9+
```
10+
coder envs stop [environment_name] [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help help for stop
17+
```
18+
19+
### Options inherited from parent commands
20+
21+
```
22+
--user string Specify the user whose resources to target (default "me")
23+
```
24+
25+
### SEE ALSO
26+
27+
* [coder envs](coder_envs.md) - Interact with Coder environments

Diff for: internal/cmd/envs.go

+28
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,34 @@ func makeEnvsCommand() *cobra.Command {
6161
}
6262
lsCmd.Flags().StringVarP(&outputFmt, "output", "o", "human", "human | json")
6363
cmd.AddCommand(lsCmd)
64+
cmd.AddCommand(stopEnvCommand(&user))
6465

6566
return cmd
6667
}
68+
69+
func stopEnvCommand(user *string) *cobra.Command {
70+
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),
75+
RunE: func(cmd *cobra.Command, args []string) error {
76+
client, err := newClient()
77+
if err != nil {
78+
return xerrors.Errorf("new client: %w", err)
79+
}
80+
81+
envName := args[0]
82+
env, err := findEnv(cmd.Context(), client, envName, *user)
83+
if err != nil {
84+
return xerrors.Errorf("find environment by name: %w", err)
85+
}
86+
87+
if err = client.StopEnvironment(cmd.Context(), env.ID); err != nil {
88+
return xerrors.Errorf("stop environment: %w", err)
89+
}
90+
flog.Success("Successfully stopped environment %q", envName)
91+
return nil
92+
},
93+
}
94+
}

0 commit comments

Comments
 (0)