From 1a35a418eb5239ee41923e6b71ad1c59efc20d55 Mon Sep 17 00:00:00 2001 From: Abhineet Jain Date: Fri, 24 Jun 2022 15:30:32 +0000 Subject: [PATCH] add success messages for CLI commands --- cli/delete.go | 10 +++++++++- cli/resetpassword.go | 2 ++ cli/start.go | 10 +++++++++- cli/stop.go | 10 +++++++++- cli/userstatus.go | 5 +++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/cli/delete.go b/cli/delete.go index bed17ee9ff483..4aad69e610c15 100644 --- a/cli/delete.go +++ b/cli/delete.go @@ -1,6 +1,7 @@ package cli import ( + "fmt" "time" "github.com/spf13/cobra" @@ -41,7 +42,14 @@ func delete() *cobra.Command { if err != nil { return err } - return cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before) + + err = cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before) + if err != nil { + return err + } + + _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nThe %s workspace has been deleted!\n", cliui.Styles.Keyword.Render(workspace.Name)) + return nil }, } cliui.AllowSkipPrompt(cmd) diff --git a/cli/resetpassword.go b/cli/resetpassword.go index ec23a2fc89bed..e33483243fa0b 100644 --- a/cli/resetpassword.go +++ b/cli/resetpassword.go @@ -2,6 +2,7 @@ package cli import ( "database/sql" + "fmt" "github.com/spf13/cobra" "golang.org/x/xerrors" @@ -80,6 +81,7 @@ func resetPassword() *cobra.Command { return xerrors.Errorf("updating password: %w", err) } + _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nPassword has been reset for user %s!\n", cliui.Styles.Keyword.Render(user.Username)) return nil }, } diff --git a/cli/start.go b/cli/start.go index 4a645cf08dbb7..7c48de20cb892 100644 --- a/cli/start.go +++ b/cli/start.go @@ -1,6 +1,7 @@ package cli import ( + "fmt" "time" "github.com/spf13/cobra" @@ -39,7 +40,14 @@ func start() *cobra.Command { if err != nil { return err } - return cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before) + + err = cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before) + if err != nil { + return err + } + + _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nThe %s workspace has been started!\n", cliui.Styles.Keyword.Render(workspace.Name)) + return nil }, } cliui.AllowSkipPrompt(cmd) diff --git a/cli/stop.go b/cli/stop.go index 2f2f6fc0f7a81..33c0d10cbeca2 100644 --- a/cli/stop.go +++ b/cli/stop.go @@ -1,6 +1,7 @@ package cli import ( + "fmt" "time" "github.com/spf13/cobra" @@ -39,7 +40,14 @@ func stop() *cobra.Command { if err != nil { return err } - return cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before) + + err = cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before) + if err != nil { + return err + } + + _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nThe %s workspace has been stopped!\n", cliui.Styles.Keyword.Render(workspace.Name)) + return nil }, } cliui.AllowSkipPrompt(cmd) diff --git a/cli/userstatus.go b/cli/userstatus.go index 152584d8244d5..3c908539a7704 100644 --- a/cli/userstatus.go +++ b/cli/userstatus.go @@ -13,15 +13,18 @@ import ( // createUserStatusCommand sets a user status. func createUserStatusCommand(sdkStatus codersdk.UserStatus) *cobra.Command { var verb string + var pastVerb string var aliases []string var short string switch sdkStatus { case codersdk.UserStatusActive: verb = "activate" + pastVerb = "activated" aliases = []string{"active"} short = "Update a user's status to 'active'. Active users can fully interact with the platform" case codersdk.UserStatusSuspended: verb = "suspend" + pastVerb = "suspended" aliases = []string{"rm", "delete"} short = "Update a user's status to 'suspended'. A suspended user cannot log into the platform" default: @@ -76,6 +79,8 @@ func createUserStatusCommand(sdkStatus codersdk.UserStatus) *cobra.Command { if err != nil { return xerrors.Errorf("%s user: %w", verb, err) } + + _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nUser %s has been %s!\n", cliui.Styles.Keyword.Render(user.Username), pastVerb) return nil }, }