Skip to content

Commit bd07284

Browse files
authored
feat: Add success messages for CLI commands (#2634)
1 parent 05b67ab commit bd07284

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

cli/delete.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"fmt"
45
"time"
56

67
"github.com/spf13/cobra"
@@ -41,7 +42,14 @@ func delete() *cobra.Command {
4142
if err != nil {
4243
return err
4344
}
44-
return cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
45+
46+
err = cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
47+
if err != nil {
48+
return err
49+
}
50+
51+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nThe %s workspace has been deleted!\n", cliui.Styles.Keyword.Render(workspace.Name))
52+
return nil
4553
},
4654
}
4755
cliui.AllowSkipPrompt(cmd)

cli/resetpassword.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"database/sql"
5+
"fmt"
56

67
"github.com/spf13/cobra"
78
"golang.org/x/xerrors"
@@ -80,6 +81,7 @@ func resetPassword() *cobra.Command {
8081
return xerrors.Errorf("updating password: %w", err)
8182
}
8283

84+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nPassword has been reset for user %s!\n", cliui.Styles.Keyword.Render(user.Username))
8385
return nil
8486
},
8587
}

cli/start.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"fmt"
45
"time"
56

67
"github.com/spf13/cobra"
@@ -39,7 +40,14 @@ func start() *cobra.Command {
3940
if err != nil {
4041
return err
4142
}
42-
return cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
43+
44+
err = cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
45+
if err != nil {
46+
return err
47+
}
48+
49+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nThe %s workspace has been started!\n", cliui.Styles.Keyword.Render(workspace.Name))
50+
return nil
4351
},
4452
}
4553
cliui.AllowSkipPrompt(cmd)

cli/stop.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"fmt"
45
"time"
56

67
"github.com/spf13/cobra"
@@ -39,7 +40,14 @@ func stop() *cobra.Command {
3940
if err != nil {
4041
return err
4142
}
42-
return cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
43+
44+
err = cliui.WorkspaceBuild(cmd.Context(), cmd.OutOrStdout(), client, build.ID, before)
45+
if err != nil {
46+
return err
47+
}
48+
49+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nThe %s workspace has been stopped!\n", cliui.Styles.Keyword.Render(workspace.Name))
50+
return nil
4351
},
4452
}
4553
cliui.AllowSkipPrompt(cmd)

cli/userstatus.go

+5
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ import (
1313
// createUserStatusCommand sets a user status.
1414
func createUserStatusCommand(sdkStatus codersdk.UserStatus) *cobra.Command {
1515
var verb string
16+
var pastVerb string
1617
var aliases []string
1718
var short string
1819
switch sdkStatus {
1920
case codersdk.UserStatusActive:
2021
verb = "activate"
22+
pastVerb = "activated"
2123
aliases = []string{"active"}
2224
short = "Update a user's status to 'active'. Active users can fully interact with the platform"
2325
case codersdk.UserStatusSuspended:
2426
verb = "suspend"
27+
pastVerb = "suspended"
2528
aliases = []string{"rm", "delete"}
2629
short = "Update a user's status to 'suspended'. A suspended user cannot log into the platform"
2730
default:
@@ -76,6 +79,8 @@ func createUserStatusCommand(sdkStatus codersdk.UserStatus) *cobra.Command {
7679
if err != nil {
7780
return xerrors.Errorf("%s user: %w", verb, err)
7881
}
82+
83+
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\nUser %s has been %s!\n", cliui.Styles.Keyword.Render(user.Username), pastVerb)
7984
return nil
8085
},
8186
}

0 commit comments

Comments
 (0)