Skip to content

Commit 188ff13

Browse files
authored
Merge pull request cli#2785 from n1lesh/auth-status-fail
Add fail message for non-existent hostname
2 parents bdce08a + 71fd2fa commit 188ff13

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/cmd/auth/status/status.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ func statusRun(opts *StatusOptions) error {
8181
apiClient := api.NewClientFromHTTP(httpClient)
8282

8383
var failed bool
84+
var isHostnameFound bool
8485

8586
for _, hostname := range hostnames {
8687
if opts.Hostname != "" && opts.Hostname != hostname {
8788
continue
8889
}
90+
isHostnameFound = true
8991

9092
token, tokenSource, _ := cfg.GetWithSource(hostname, "oauth_token")
9193
tokenIsWriteable := cfg.CheckWriteable(hostname, "oauth_token") == nil
@@ -139,6 +141,12 @@ func statusRun(opts *StatusOptions) error {
139141
// not to since I wanted this command to be read-only.
140142
}
141143

144+
if !isHostnameFound {
145+
fmt.Fprintf(stderr,
146+
"Hostname %q not found among authenticated GitHub hosts\n", opts.Hostname)
147+
return cmdutil.SilentError
148+
}
149+
142150
for _, hostname := range hostnames {
143151
lines, ok := statusInfo[hostname]
144152
if !ok {

pkg/cmd/auth/status/status_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ func Test_statusRun(t *testing.T) {
190190
httpmock.StringResponse(`{"data":{"viewer":{"login":"tess"}}}`))
191191
},
192192
wantErrOut: regexp.MustCompile(`(?s)Token: xyz456.*Token: abc123`),
193+
}, {
194+
name: "missing hostname",
195+
opts: &StatusOptions{
196+
Hostname: "github.example.com",
197+
},
198+
cfg: func(c config.Config) {
199+
_ = c.Set("github.com", "oauth_token", "abc123")
200+
},
201+
httpStubs: func(reg *httpmock.Registry) {},
202+
wantErrOut: regexp.MustCompile(`(?s)Hostname "github.example.com" not found among authenticated GitHub hosts`),
203+
wantErr: "SilentError",
193204
},
194205
}
195206

0 commit comments

Comments
 (0)