Skip to content

feat: Add suspend/active user to cli #1422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 16, 2022
Merged
Prev Previous commit
Next Next commit
Move command outside status subgroup
  • Loading branch information
Emyrk committed May 13, 2022
commit 2ed42499aba4c8c9527fc74b51d896e79b7887a0
3 changes: 2 additions & 1 deletion cli/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func users() *cobra.Command {
cmd.AddCommand(
userCreate(),
userList(),
userStatus(),
createUserStatusCommand(codersdk.UserStatusActive),
createUserStatusCommand(codersdk.UserStatusSuspended),
)
return cmd
}
Expand Down
14 changes: 1 addition & 13 deletions cli/userstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ import (
"github.com/coder/coder/codersdk"
)

func userStatus() *cobra.Command {
cmd := &cobra.Command{
Use: "status",
Short: "Update the status of a user",
}
cmd.AddCommand(
createUserStatusCommand(codersdk.UserStatusActive),
createUserStatusCommand(codersdk.UserStatusSuspended),
)
return cmd
}

// createUserStatusCommand sets a user status.
func createUserStatusCommand(sdkStatus codersdk.UserStatus) *cobra.Command {
var verb string
Expand All @@ -48,7 +36,7 @@ func createUserStatusCommand(sdkStatus codersdk.UserStatus) *cobra.Command {
Short: short,
Args: cobra.ExactArgs(1),
Aliases: aliases,
Example: fmt.Sprintf("coder users status %s example_user", verb),
Example: fmt.Sprintf("coder users %s example_user", verb),
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cli/userstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestUserStatus(t *testing.T) {

//nolint:paralleltest
t.Run("StatusSelf", func(t *testing.T) {
cmd, root := clitest.New(t, "users", "status", "suspend", "me")
cmd, root := clitest.New(t, "users", "suspend", "me")
clitest.SetupConfig(t, client, root)
// Yes to the prompt
cmd.SetIn(bytes.NewReader([]byte("yes\n")))
Expand All @@ -36,7 +36,7 @@ func TestUserStatus(t *testing.T) {
t.Run("StatusOther", func(t *testing.T) {
require.Equal(t, otherUser.Status, codersdk.UserStatusActive, "start as active")

cmd, root := clitest.New(t, "users", "status", "suspend", otherUser.Username)
cmd, root := clitest.New(t, "users", "suspend", otherUser.Username)
clitest.SetupConfig(t, client, root)
// Yes to the prompt
cmd.SetIn(bytes.NewReader([]byte("yes\n")))
Expand All @@ -48,8 +48,8 @@ func TestUserStatus(t *testing.T) {
require.NoError(t, err, "fetch suspended user")
require.Equal(t, otherUser.Status, codersdk.UserStatusSuspended, "suspended user")

// Set back to active
cmd, root = clitest.New(t, "users", "status", "active", otherUser.Username)
// Set back to active. Try using a uuid as well
cmd, root = clitest.New(t, "users", "activate", otherUser.ID.String())
clitest.SetupConfig(t, client, root)
// Yes to the prompt
cmd.SetIn(bytes.NewReader([]byte("yes\n")))
Expand Down