@@ -118,6 +118,8 @@ func statusRun(opts *StatusOptions) error {
118118 return nil
119119 }
120120
121+ statusInfo := map [string ][]string {}
122+
121123 hostnames , err := cfg .Hosts ()
122124 if len (hostnames ) == 0 || err != nil {
123125 fmt .Fprintf (stderr ,
@@ -137,43 +139,52 @@ func statusRun(opts *StatusOptions) error {
137139 if opts .Hostname != "" && opts .Hostname != hostname {
138140 continue
139141 }
142+
143+ statusInfo [hostname ] = []string {}
144+ addMsg := func (x string , ys ... interface {}) {
145+ statusInfo [hostname ] = append (statusInfo [hostname ], fmt .Sprintf (x , ys ... ))
146+ }
147+
140148 _ , err = apiClient .HasMinimumScopes (hostname )
141149 if err != nil {
142150 var missingScopes * api.MissingScopesError
143151 if errors .As (err , & missingScopes ) {
144- fmt . Fprintf ( stderr , "%s %s: %s\n " , utils .Red ("X" ), hostname , err )
145- fmt . Fprintf ( stderr , " To enable the missing scopes, please run %s %s\n " ,
152+ addMsg ( "%s %s: %s\n " , utils .Red ("X" ), hostname , err )
153+ addMsg ( "- To enable the missing scopes, please run %s %s\n " ,
146154 utils .Bold ("gh auth refresh -h" ),
147155 utils .Bold (hostname ))
148156 } else {
149- fmt .Fprintf (stderr , "%s %s: authentication failed\n " , utils .Red ("X" ), hostname )
150- fmt .Fprintln (stderr )
151- fmt .Fprintf (stderr , "The configured token for %s is no longer valid.\n " , utils .Bold (hostname ))
152- fmt .Fprintf (stderr , "To re-authenticate, please run %s %s\n " ,
157+ addMsg ("%s %s: authentication failed\n " , utils .Red ("X" ), hostname )
158+ addMsg ("- The configured token for %s is no longer valid." , utils .Bold (hostname ))
159+ addMsg ("- To re-authenticate, please run %s %s" ,
153160 utils .Bold ("gh auth login -h" ), utils .Bold (hostname ))
154- fmt . Fprintf ( stderr , " To forget about this host, please run %s %s\n " ,
161+ addMsg ( "- To forget about this host, please run %s %s" ,
155162 utils .Bold ("gh auth logout -h" ), utils .Bold (hostname ))
156163 }
157164 failed = true
158165 } else {
159166 username , err := api .CurrentLoginName (apiClient , hostname )
160167 if err != nil {
161- fmt . Fprintf ( stderr , "%s %s: api call failed: %s\n " , utils .Red ("X" ), hostname , err )
168+ addMsg ( "%s %s: api call failed: %s\n " , utils .Red ("X" ), hostname , err )
162169 }
163- fmt . Fprintf ( stderr , "%s Logged in to %s as %s\n " , utils .GreenCheck (), hostname , utils .Bold (username ))
170+ addMsg ( "%s Logged in to %s as %s" , utils .GreenCheck (), hostname , utils .Bold (username ))
164171 proto , _ := cfg .Get (hostname , "git_protocol" )
165172 if proto != "" {
166- fmt .Fprintln (stderr )
167- fmt .Fprintf (stderr ,
168- "Git operations for %s configured to use %s protocol.\n " , hostname , utils .Bold (proto ))
169- fmt .Fprintln (stderr )
173+ addMsg ("Git operations for %s configured to use %s protocol." , hostname , utils .Bold (proto ))
170174 }
171175 }
172176
173177 // NB we could take this opportunity to add or fix the "user" key in the hosts config. I chose
174178 // not to since I wanted this command to be read-only.
175179 }
176180
181+ for hostname , lines := range statusInfo {
182+ fmt .Fprintf (stderr , "%s\n " , utils .Bold (hostname ))
183+ for _ , line := range lines {
184+ fmt .Fprintf (stderr , "\t %s\n " , line )
185+ }
186+ }
187+
177188 if failed {
178189 return cmdutil .SilentError
179190 }
0 commit comments