Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0a840e4

Browse files
authored
feat(cli): add more information tocoder whoami (#19971)
Builds upon#19970I got kinda carried away when I saw the extra stuff we could add inhere, so I went ahead and added it:* User ID* Organization IDs* RolesThis technically duplicates functionality from `coder users show` but Ifigure folks may find it useful.
1 parent05537c1 commit0a840e4

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

‎cli/testdata/coder_whoami_--help.golden‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ USAGE:
66
Fetch authenticated user info for Coder deployment
77

88
OPTIONS:
9-
-c, --column [URL|Username] (default: url,username)
9+
-c, --column [URL|Username|ID|Orgs|Roles] (default: url,username,id)
1010
Columns to display in table output.
1111

1212
-o, --output text|json|table (default: text)

‎cli/whoami.go‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"fmt"
5+
"strings"
56

67
"github.com/coder/coder/v2/cli/cliui"
78
"github.com/coder/coder/v2/codersdk"
@@ -10,8 +11,13 @@ import (
1011
)
1112

1213
typewhoamiRowstruct {
13-
URLstring`json:"url" table:"URL,default_sort"`
14-
Usernamestring`json:"username" table:"Username"`
14+
URLstring`json:"url" table:"URL,default_sort"`
15+
Usernamestring`json:"username" table:"Username"`
16+
UserIDstring`json:"user_id" table:"ID"`
17+
OrganizationIDsstring`json:"-" table:"Orgs"`
18+
OrganizationIDsJSON []string`json:"organization_ids" table:"-"`
19+
Rolesstring`json:"-" table:"Roles"`
20+
RolesJSONmap[string][]string`json:"roles" table:"-"`
1521
}
1622

1723
func (rwhoamiRow)String()string {
@@ -26,7 +32,7 @@ func (r *RootCmd) whoami() *serpent.Command {
2632
formatter:=cliui.NewOutputFormatter(
2733
cliui.TextFormat(),
2834
cliui.JSONFormat(),
29-
cliui.TableFormat([]whoamiRow{}, []string{"url","username"}),
35+
cliui.TableFormat([]whoamiRow{}, []string{"url","username","id"}),
3036
)
3137
cmd:=&serpent.Command{
3238
Annotations:workspaceCommand,
@@ -50,10 +56,29 @@ func (r *RootCmd) whoami() *serpent.Command {
5056
returnerr
5157
}
5258

59+
orgIDs:=make([]string,0,len(resp.OrganizationIDs))
60+
for_,orgID:=rangeresp.OrganizationIDs {
61+
orgIDs=append(orgIDs,orgID.String())
62+
}
63+
64+
roles:=make([]string,0,len(resp.Roles))
65+
jsonRoles:=make(map[string][]string)
66+
for_,role:=rangeresp.Roles {
67+
ifrole.OrganizationID=="" {
68+
role.OrganizationID="*"
69+
}
70+
roles=append(roles,fmt.Sprintf("%s:%s",role.OrganizationID,role.DisplayName))
71+
jsonRoles[role.OrganizationID]=append(jsonRoles[role.OrganizationID],role.DisplayName)
72+
}
5373
out,err:=formatter.Format(ctx, []whoamiRow{
5474
{
55-
URL:clientURL.String(),
56-
Username:resp.Username,
75+
URL:clientURL.String(),
76+
Username:resp.Username,
77+
UserID:resp.ID.String(),
78+
OrganizationIDs:strings.Join(orgIDs,","),
79+
OrganizationIDsJSON:orgIDs,
80+
Roles:strings.Join(roles,","),
81+
RolesJSON:jsonRoles,
5782
},
5883
})
5984
iferr!=nil {

‎docs/reference/cli/whoami.md‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp