MCPcopy Create free account
hub / github.com/cli/cli / statusRun

Function statusRun

pkg/cmd/auth/status/status.go:191–329  ·  view source on GitHub ↗
(opts *StatusOptions)

Source from the content-addressed store, hash-verified

189}
190
191func statusRun(opts *StatusOptions) error {
192 cfg, err := opts.Config()
193 if err != nil {
194 return err
195 }
196 authCfg := cfg.Authentication()
197
198 stderr := opts.IO.ErrOut
199 stdout := opts.IO.Out
200 cs := opts.IO.ColorScheme()
201
202 hostnames := authCfg.Hosts()
203 if len(hostnames) == 0 {
204 fmt.Fprintf(stderr,
205 "You are not logged into any GitHub hosts. To log in, run: %s\n", cs.Bold("gh auth login"))
206 if opts.Exporter != nil {
207 // In machine-friendly mode, we always exit with no error.
208 opts.Exporter.Write(opts.IO, newAuthStatus())
209 return nil
210 }
211 return cmdutil.SilentError
212 }
213
214 if opts.Hostname != "" && !slices.Contains(hostnames, opts.Hostname) {
215 fmt.Fprintf(stderr,
216 "You are not logged into any accounts on %s\n", opts.Hostname)
217 if opts.Exporter != nil {
218 // In machine-friendly mode, we always exit with no error.
219 opts.Exporter.Write(opts.IO, newAuthStatus())
220 return nil
221 }
222 return cmdutil.SilentError
223 }
224
225 httpClient, err := opts.HttpClient()
226 if err != nil {
227 return err
228 }
229
230 var finalErr error
231 statuses := newAuthStatus()
232
233 for _, hostname := range hostnames {
234 if opts.Hostname != "" && opts.Hostname != hostname {
235 continue
236 }
237
238 var activeUser string
239 gitProtocol := cfg.GitProtocol(hostname).Value
240 activeUserToken, activeUserTokenSource := authCfg.ActiveToken(hostname)
241 if authTokenWriteable(activeUserTokenSource) {
242 activeUser, _ = authCfg.ActiveUser(hostname)
243 }
244 entry := buildEntry(httpClient, buildEntryOptions{
245 active: true,
246 gitProtocol: gitProtocol,
247 hostname: hostname,
248 token: activeUserToken,

Callers 2

NewCmdStatusFunction · 0.70
Test_statusRunFunction · 0.70

Calls 15

newAuthStatusFunction · 0.85
authTokenWriteableFunction · 0.85
buildEntryFunction · 0.85
maskTokenFunction · 0.85
ColorSchemeMethod · 0.80
BoldMethod · 0.80
ContainsMethod · 0.80
ConfigMethod · 0.65
AuthenticationMethod · 0.65
HostsMethod · 0.65
WriteMethod · 0.65
GitProtocolMethod · 0.65

Tested by 1

Test_statusRunFunction · 0.56