Fix detecting cases when cfg.Hosts() is empty

This commit is contained in:
Mislav Marohnić 2021-07-20 15:47:15 +02:00
parent aec0f10041
commit c598a1edc2
3 changed files with 10 additions and 1 deletions

View file

@ -74,6 +74,9 @@ func logoutRun(opts *LogoutOptions) error {
candidates, err := cfg.Hosts()
if err != nil {
return err
}
if len(candidates) == 0 {
return fmt.Errorf("not logged in to any hosts")
}

View file

@ -83,6 +83,9 @@ func refreshRun(opts *RefreshOptions) error {
candidates, err := cfg.Hosts()
if err != nil {
return err
}
if len(candidates) == 0 {
return fmt.Errorf("not logged in to any hosts. Use 'gh auth login' to authenticate with a host")
}

View file

@ -69,7 +69,10 @@ func statusRun(opts *StatusOptions) error {
statusInfo := map[string][]string{}
hostnames, err := cfg.Hosts()
if len(hostnames) == 0 || err != nil {
if err != nil {
return err
}
if len(hostnames) == 0 {
fmt.Fprintf(stderr,
"You are not logged into any GitHub hosts. Run %s to authenticate.\n", cs.Bold("gh auth login"))
return cmdutil.SilentError