fix show token when using json
This commit is contained in:
parent
48bc79a291
commit
78675e73e1
2 changed files with 17 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue