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

Method userList

cli/userlist.go:16–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14)
15
16func (r *RootCmd) userList() *serpent.Command {
17 formatter := cliui.NewOutputFormatter(
18 cliui.TableFormat([]codersdk.User{}, []string{"username", "email", "created at", "status"}),
19 cliui.JSONFormat(),
20 )
21 var githubUserID int64
22
23 cmd := &serpent.Command{
24 Use: "list",
25 Short: "Prints the list of users.",
26 Aliases: []string{"ls"},
27 Middleware: serpent.Chain(
28 serpent.RequireNArgs(0),
29 ),
30 Options: serpent.OptionSet{
31 {
32 Name: "github-user-id",
33 Description: "Filter users by their GitHub user ID.",
34 Default: "",
35 Flag: "github-user-id",
36 Required: false,
37 Value: serpent.Int64Of(&githubUserID),
38 },
39 },
40 Handler: func(inv *serpent.Invocation) error {
41 client, err := r.InitClient(inv)
42 if err != nil {
43 return err
44 }
45
46 req := codersdk.UsersRequest{}
47 if githubUserID != 0 {
48 req.Search = fmt.Sprintf("github_com_user_id:%d", githubUserID)
49 }
50
51 res, err := client.Users(inv.Context(), req)
52 if err != nil {
53 return err
54 }
55
56 out, err := formatter.Format(inv.Context(), res.Users)
57 if err != nil {
58 return err
59 }
60
61 if out == "" {
62 cliui.Infof(inv.Stderr, "No users found.")
63 return nil
64 }
65
66 _, err = fmt.Fprintln(inv.Stdout, out)
67 return err
68 },
69 }
70
71 formatter.AttachOptions(&cmd.Options)
72 return cmd
73}

Callers 1

usersMethod · 0.95

Calls 9

InitClientMethod · 0.95
FormatMethod · 0.95
AttachOptionsMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
InfofFunction · 0.92
UsersMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected