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

Method userSingle

cli/userlist.go:75–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73}
74
75func (r *RootCmd) userSingle() *serpent.Command {
76 formatter := cliui.NewOutputFormatter(
77 &userShowFormat{},
78 cliui.JSONFormat(),
79 )
80
81 cmd := &serpent.Command{
82 Use: "show <username|user_id|'me'>",
83 Short: "Show a single user. Use 'me' to indicate the currently authenticated user.",
84 Long: FormatExamples(
85 Example{
86 Command: "coder users show me",
87 },
88 ),
89 Middleware: serpent.Chain(
90 serpent.RequireNArgs(1),
91 ),
92 Handler: func(inv *serpent.Invocation) error {
93 client, err := r.InitClient(inv)
94 if err != nil {
95 return err
96 }
97
98 user, err := client.User(inv.Context(), inv.Args[0])
99 if err != nil {
100 return err
101 }
102
103 orgNames := make([]string, len(user.OrganizationIDs))
104 for i, orgID := range user.OrganizationIDs {
105 org, err := client.Organization(inv.Context(), orgID)
106 if err != nil {
107 return xerrors.Errorf("get organization %q: %w", orgID.String(), err)
108 }
109
110 orgNames[i] = org.Name
111 }
112
113 out, err := formatter.Format(inv.Context(), userWithOrgNames{
114 User: user,
115 OrganizationNames: orgNames,
116 })
117 if err != nil {
118 return err
119 }
120
121 _, err = fmt.Fprintln(inv.Stdout, out)
122 return err
123 },
124 }
125
126 formatter.AttachOptions(&cmd.Options)
127 return cmd
128}
129
130type userWithOrgNames struct {
131 codersdk.User

Callers 1

usersMethod · 0.95

Calls 11

InitClientMethod · 0.95
FormatMethod · 0.95
AttachOptionsMethod · 0.95
NewOutputFormatterFunction · 0.92
JSONFormatFunction · 0.92
FormatExamplesFunction · 0.85
UserMethod · 0.65
ContextMethod · 0.65
OrganizationMethod · 0.45
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected