fix show token when using json

This commit is contained in:
Benjamin Levesque 2025-08-20 21:01:31 +02:00
parent 48bc79a291
commit 78675e73e1
No known key found for this signature in database
GPG key ID: 765E3CB147AA4D4A
2 changed files with 17 additions and 3 deletions

View file

@ -187,9 +187,12 @@ func statusRun(opts *StatusOptions) error {
stdout := opts.IO.Out
cs := opts.IO.ColorScheme()
if opts.ShowToken && opts.Exporter != nil {
fmt.Fprintf(stderr, "`--json` and `--show-token` cannot be used together. To include the token in the JSON output, use `--json token`.")
return nil
if opts.Exporter != nil {
if opts.ShowToken {
fmt.Fprintf(stderr, "`--json` and `--show-token` cannot be used together. To include the token in the JSON output, use `--json token`.")
return nil
}
opts.ShowToken = true
}
statuses := make(map[string]Entries)

View file

@ -651,6 +651,17 @@ func Test_statusRun(t *testing.T) {
},
wantOut: `{"github.com":[{"active":true,"host":"github.com","login":"monalisa","scopes":"","state":"timeout"}]}` + "\n",
},
{
name: "token is not masked with json flag",
opts: StatusOptions{
Hostname: "github.com",
Exporter: addFieldsToExporter(defaultJsonExporter(), []string{"token"}),
},
cfgStubs: func(t *testing.T, c gh.Config) {
login(t, c, "github.com", "monalisa", "abc123", "https")
},
wantOut: `{"github.com":[{"active":true,"host":"github.com","login":"monalisa","state":"success","token":"abc123"}]}` + "\n",
},
{
name: "Both show token and json flags",
opts: StatusOptions{