feat: add --yes to coder users suspend and activate (#30155)

`coder users suspend` and `coder users activate` always prompt but,
unlike other commands with a confirmation prompt, had no `-y/--yes`.

Both now accept `-y`.
The suspend help also says that suspending stops the user's running
workspaces and that activating doesn't restart them.

**Behavior change:** Additive.
New `-y` flag; without it, both commands prompt as before.

<details>
<summary>Decisions</summary>

- The workspace note is based on the lifecycle executor, which
auto-stops a suspended user's running workspaces; activation doesn't
restart them.

</details>

Closes [CLI-23](https://linear.app/codercom/issue/CLI-23)

_This PR was generated by Coder Agents on behalf of @nickvigilante._
This commit is contained in:
Nick Vigilante
2026-09-30 12:38:14 -04:00
committed by GitHub
parent cf60604a75
commit dde500a646
9 changed files with 74 additions and 16 deletions
+3 -1
View File
@@ -18,7 +18,9 @@ SUBCOMMANDS:
show Show a single user. Use 'me' to indicate the currently
authenticated user.
suspend Update a user's status to 'suspended'. A suspended user
cannot log into the platform
cannot log into the platform. Suspending a user stops their
running workspaces; activating the user again does not
restart them.
———
Run `coder --help` for a list of global options.
+3
View File
@@ -14,5 +14,8 @@ OPTIONS:
-c, --column [username|email|created at|status] (default: username,email,created at,status)
Specify a column to filter in the table.
-y, --yes bool
Bypass confirmation prompts.
———
Run `coder --help` for a list of global options.
+5 -1
View File
@@ -4,7 +4,8 @@ USAGE:
coder users suspend [flags] <username|user_id>
Update a user's status to 'suspended'. A suspended user cannot log into the
platform
platform. Suspending a user stops their running workspaces; activating the
user again does not restart them.
$ coder users suspend example_user
@@ -12,5 +13,8 @@ OPTIONS:
-c, --column [username|email|created at|status] (default: username,email,created at,status)
Specify a column to filter in the table.
-y, --yes bool
Bypass confirmation prompts.
———
Run `coder --help` for a list of global options.
+3 -1
View File
@@ -27,7 +27,8 @@ func (r *RootCmd) createUserStatusCommand(sdkStatus codersdk.UserStatus) *serpen
case codersdk.UserStatusSuspended:
verb = "suspend"
pastVerb = "suspended"
short = "Update a user's status to 'suspended'. A suspended user cannot log into the platform"
short = "Update a user's status to 'suspended'. A suspended user cannot log into the platform. " +
"Suspending a user stops their running workspaces; activating the user again does not restart them."
default:
panic(fmt.Sprintf("%s is not supported", sdkStatus))
}
@@ -96,6 +97,7 @@ func (r *RootCmd) createUserStatusCommand(sdkStatus codersdk.UserStatus) *serpen
},
}
cmd.Options = serpent.OptionSet{
cliui.SkipPromptOption(),
{
Flag: "column",
FlagShorthand: "c",
+31
View File
@@ -67,4 +67,35 @@ func TestUserStatus(t *testing.T) {
require.NoError(t, err, "fetch active user")
require.Equal(t, codersdk.UserStatusActive, otherUser.Status, "active user")
})
t.Run("SkipPromptFlag", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
owner := coderdtest.CreateFirstUser(t, client)
userAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleUserAdmin())
other, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
otherUser, err := other.User(context.Background(), codersdk.Me)
require.NoError(t, err, "fetch user")
// No stdin is attached, so the command would block or fail if it tried to
// prompt.
inv, root := clitest.New(t, "users", "suspend", otherUser.Username, "-y")
clitest.SetupConfig(t, userAdmin, root)
err = inv.Run()
require.NoError(t, err, "suspend user")
otherUser, err = client.User(context.Background(), otherUser.Username)
require.NoError(t, err, "fetch suspended user")
require.Equal(t, codersdk.UserStatusSuspended, otherUser.Status, "suspended user")
inv, root = clitest.New(t, "users", "activate", otherUser.Username, "--yes")
clitest.SetupConfig(t, userAdmin, root)
err = inv.Run()
require.NoError(t, err, "activate user")
otherUser, err = client.User(context.Background(), otherUser.Username)
require.NoError(t, err, "fetch active user")
require.Equal(t, codersdk.UserStatusActive, otherUser.Status, "active user")
})
}
+1 -1
View File
@@ -2568,7 +2568,7 @@
},
{
"title": "`suspend`",
"description": "Update a user's status to 'suspended'. A suspended user cannot log into the platform",
"description": "Update a user's status to 'suspended'. A suspended user cannot log into the platform. Suspending a user stops their running workspaces; activating the user again does not restart them.",
"path": "reference/cli/users/suspend.md"
}
]
+8
View File
@@ -26,6 +26,14 @@ coder users activate [flags] <username|user_id>
## Options
### -y, --yes
| | |
|------|-------------------|
| Type | <code>bool</code> |
Bypass confirmation prompts.
### -c, --column
| | |
+10 -10
View File
@@ -20,13 +20,13 @@ coder users [subcommand]
## Subcommands
| Name | Purpose |
|----------------------------------------------|---------------------------------------------------------------------------------------|
| [<code>create</code>](./create.md) | Create a new user. |
| [<code>list</code>](./list.md) | Prints the list of users. |
| [<code>show</code>](./show.md) | Show a single user. Use 'me' to indicate the currently authenticated user. |
| [<code>delete</code>](./delete.md) | Delete a user by username or user_id. |
| [<code>edit-roles</code>](./edit-roles.md) | Edit a user's roles by username or id |
| [<code>oidc-claims</code>](./oidc-claims.md) | Display the OIDC claims for the authenticated user. |
| [<code>activate</code>](./activate.md) | Update a user's status to 'active'. Active users can fully interact with the platform |
| [<code>suspend</code>](./suspend.md) | Update a user's status to 'suspended'. A suspended user cannot log into the platform |
| Name | Purpose |
|----------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [<code>create</code>](./create.md) | Create a new user. |
| [<code>list</code>](./list.md) | Prints the list of users. |
| [<code>show</code>](./show.md) | Show a single user. Use 'me' to indicate the currently authenticated user. |
| [<code>delete</code>](./delete.md) | Delete a user by username or user_id. |
| [<code>edit-roles</code>](./edit-roles.md) | Edit a user's roles by username or id |
| [<code>oidc-claims</code>](./oidc-claims.md) | Display the OIDC claims for the authenticated user. |
| [<code>activate</code>](./activate.md) | Update a user's status to 'active'. Active users can fully interact with the platform |
| [<code>suspend</code>](./suspend.md) | Update a user's status to 'suspended'. A suspended user cannot log into the platform. Suspending a user stops their running workspaces; activating the user again does not restart them. |
+10 -2
View File
@@ -1,12 +1,12 @@
---
# Code generated by make gen. DO NOT EDIT.
title: "`coder users suspend`"
description: "Update a user's status to 'suspended'. A suspended user cannot log into the platform"
description: "Update a user's status to 'suspended'. A suspended user cannot log into the platform. Suspending a user stops their running workspaces; activating the user again does not restart them."
---
<!-- DO NOT EDIT | GENERATED CONTENT -->
Update a user's status to 'suspended'. A suspended user cannot log into the platform
Update a user's status to 'suspended'. A suspended user cannot log into the platform. Suspending a user stops their running workspaces; activating the user again does not restart them.
## Usage
@@ -22,6 +22,14 @@ coder users suspend [flags] <username|user_id>
## Options
### -y, --yes
| | |
|------|-------------------|
| Type | <code>bool</code> |
Bypass confirmation prompts.
### -c, --column
| | |