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

feat(cli): add formatting options to coder whoami#19970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 1 commit intomainfromcj/cli/whoami-format
Sep 26, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletioncli/testdata/coder_whoami_--help.golden
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
coder v0.0.0-devel

USAGE:
coder whoami
coder whoami [flags]

Fetch authenticated user info for Coder deployment

OPTIONS:
-c, --column [URL|Username] (default: url,username)
Columns to display in table output.

-o, --output text|json|table (default: text)
Output format.

———
Run `coder --help` for a list of global options.
31 changes: 29 additions & 2 deletionscli/whoami.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,25 @@ import (
"github.com/coder/serpent"
)

type whoamiRow struct {
URL string `json:"url" table:"URL,default_sort"`
Username string `json:"username" table:"Username"`
}

func (r whoamiRow) String() string {
return fmt.Sprintf(
Caret+"Coder is running at %s, You're authenticated as %s !\n",
pretty.Sprint(cliui.DefaultStyles.Keyword, r.URL),
pretty.Sprint(cliui.DefaultStyles.Keyword, r.Username),
)
}

func (r *RootCmd) whoami() *serpent.Command {
formatter := cliui.NewOutputFormatter(
cliui.TextFormat(),
cliui.JSONFormat(),
cliui.TableFormat([]whoamiRow{}, []string{"url", "username"}),
)
cmd := &serpent.Command{
Annotations: workspaceCommand,
Use: "whoami",
Expand All@@ -28,14 +46,23 @@ func (r *RootCmd) whoami() *serpent.Command {
resp, err := client.User(ctx, codersdk.Me)
// Get Coder instance url
clientURL := client.URL

if err != nil {
return err
}

_, _ = fmt.Fprintf(inv.Stdout, Caret+"Coder is running at %s, You're authenticated as %s !\n", pretty.Sprint(cliui.DefaultStyles.Keyword, clientURL), pretty.Sprint(cliui.DefaultStyles.Keyword, resp.Username))
out, err := formatter.Format(ctx, []whoamiRow{
{
URL: clientURL.String(),
Username: resp.Username,
},
})
if err != nil {
return err
}
_, err = inv.Stdout.Write([]byte(out))
return err
},
}
formatter.AttachOptions(&cmd.Options)
return cmd
}
22 changes: 21 additions & 1 deletiondocs/reference/cli/whoami.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

Loading

[8]ページ先頭

©2009-2025 Movatter.jp