()
| 73 | } |
| 74 | |
| 75 | func (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 | |
| 130 | type userWithOrgNames struct { |
| 131 | codersdk.User |
no test coverage detected