File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments