-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathuserdelete.go
More file actions
43 lines (37 loc) · 929 Bytes
/
userdelete.go
File metadata and controls
43 lines (37 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package cli
import (
"fmt"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/pretty"
"github.com/coder/serpent"
)
func (r *RootCmd) userDelete() *serpent.Command {
cmd := &serpent.Command{
Use: "delete <username|user_id>",
Short: "Delete a user by username or user_id.",
Middleware: serpent.Chain(
serpent.RequireNArgs(1),
),
Handler: func(inv *serpent.Invocation) error {
ctx := inv.Context()
client, err := r.InitClient(inv)
if err != nil {
return err
}
user, err := client.User(ctx, inv.Args[0])
if err != nil {
return xerrors.Errorf("fetch user: %w", err)
}
err = client.DeleteUser(ctx, user.ID)
if err != nil {
return xerrors.Errorf("delete user: %w", err)
}
_, _ = fmt.Fprintln(inv.Stderr,
"Successfully deleted "+pretty.Sprint(cliui.DefaultStyles.Keyword, user.Username)+".",
)
return nil
},
}
return cmd
}