From c598a1edc2f1f8efff270acdca03d2ea9ff96e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 20 Jul 2021 15:47:15 +0200 Subject: [PATCH] Fix detecting cases when `cfg.Hosts()` is empty --- pkg/cmd/auth/logout/logout.go | 3 +++ pkg/cmd/auth/refresh/refresh.go | 3 +++ pkg/cmd/auth/status/status.go | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/auth/logout/logout.go b/pkg/cmd/auth/logout/logout.go index 1454a3656..8ad1263a9 100644 --- a/pkg/cmd/auth/logout/logout.go +++ b/pkg/cmd/auth/logout/logout.go @@ -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") } diff --git a/pkg/cmd/auth/refresh/refresh.go b/pkg/cmd/auth/refresh/refresh.go index 58267182c..2763679f8 100644 --- a/pkg/cmd/auth/refresh/refresh.go +++ b/pkg/cmd/auth/refresh/refresh.go @@ -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") } diff --git a/pkg/cmd/auth/status/status.go b/pkg/cmd/auth/status/status.go index 6c31cfad4..2be0813c0 100644 --- a/pkg/cmd/auth/status/status.go +++ b/pkg/cmd/auth/status/status.go @@ -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