MCPcopy Index your code
hub / github.com/coder/coder / createUserStatusCommand

Method createUserStatusCommand

cli/userstatus.go:16–108  ·  view source on GitHub ↗

createUserStatusCommand sets a user status.

(sdkStatus codersdk.UserStatus)

Source from the content-addressed store, hash-verified

14
15// createUserStatusCommand sets a user status.
16func (r *RootCmd) createUserStatusCommand(sdkStatus codersdk.UserStatus) *serpent.Command {
17 var verb string
18 var pastVerb string
19 var aliases []string
20 var short string
21 switch sdkStatus {
22 case codersdk.UserStatusActive:
23 verb = "activate"
24 pastVerb = "activated"
25 aliases = []string{"active"}
26 short = "Update a user's status to 'active'. Active users can fully interact with the platform"
27 case codersdk.UserStatusSuspended:
28 verb = "suspend"
29 pastVerb = "suspended"
30 short = "Update a user's status to 'suspended'. A suspended user cannot log into the platform"
31 default:
32 panic(fmt.Sprintf("%s is not supported", sdkStatus))
33 }
34
35 var columns []string
36 allColumns := []string{"username", "email", "created at", "status"}
37 cmd := &serpent.Command{
38 Use: fmt.Sprintf("%s <username|user_id>", verb),
39 Short: short,
40 Aliases: aliases,
41 Long: FormatExamples(
42 Example{
43 Command: fmt.Sprintf("coder users %s example_user", verb),
44 },
45 ),
46 Middleware: serpent.Chain(
47 serpent.RequireNArgs(1),
48 ),
49 Handler: func(inv *serpent.Invocation) error {
50 client, err := r.InitClient(inv)
51 if err != nil {
52 return err
53 }
54 identifier := inv.Args[0]
55 if identifier == "" {
56 return xerrors.Errorf("user identifier cannot be an empty string")
57 }
58
59 user, err := client.User(inv.Context(), identifier)
60 if err != nil {
61 return xerrors.Errorf("fetch user: %w", err)
62 }
63
64 // Display the user. This uses cliui.DisplayTable directly instead
65 // of cliui.NewOutputFormatter because we prompt immediately
66 // afterwards.
67 table, err := cliui.DisplayTable([]codersdk.User{user}, "", columns)
68 if err != nil {
69 return xerrors.Errorf("render user table: %w", err)
70 }
71 _, _ = fmt.Fprintln(inv.Stdout, table)
72
73 // User status is already set to this

Callers 1

usersMethod · 0.95

Calls 9

InitClientMethod · 0.95
DisplayTableFunction · 0.92
PromptFunction · 0.92
FormatExamplesFunction · 0.85
UserMethod · 0.65
ContextMethod · 0.65
UpdateUserStatusMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected