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

Method Format

cli/userlist.go:148–208  ·  view source on GitHub ↗

Format implements OutputFormat.

(_ context.Context, out interface{})

Source from the content-addressed store, hash-verified

146
147// Format implements OutputFormat.
148func (*userShowFormat) Format(_ context.Context, out interface{}) (string, error) {
149 user, ok := out.(userWithOrgNames)
150 if !ok {
151 return "", xerrors.Errorf("expected type %T, got %T", user, out)
152 }
153
154 tw := cliui.Table()
155 addRow := func(name string, value interface{}) {
156 key := ""
157 if name != "" {
158 key = name + ":"
159 }
160 tw.AppendRow(table.Row{
161 key, value,
162 })
163 }
164
165 // Add rows for each of the user's fields.
166 addRow("ID", user.ID.String())
167 addRow("Username", user.Username)
168 addRow("Full name", user.Name)
169 addRow("Email", user.Email)
170 addRow("Status", user.Status)
171 addRow("Created At", user.CreatedAt.Format(time.Stamp))
172
173 addRow("", "")
174 firstRole := true
175 for _, role := range user.Roles {
176 if role.DisplayName == "" {
177 // Skip roles with no display name.
178 continue
179 }
180
181 key := ""
182 if firstRole {
183 key = "Roles"
184 firstRole = false
185 }
186 addRow(key, role.DisplayName)
187 }
188 if firstRole {
189 addRow("Roles", "(none)")
190 }
191
192 addRow("", "")
193 firstOrg := true
194 for _, orgName := range user.OrganizationNames {
195 key := ""
196 if firstOrg {
197 key = "Organizations"
198 firstOrg = false
199 }
200
201 addRow(key, orgName)
202 }
203 if firstOrg {
204 addRow("Organizations", "(none)")
205 }

Callers

nothing calls this directly

Calls 5

TableFunction · 0.92
FormatMethod · 0.65
RenderMethod · 0.65
ErrorfMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected