From 414de332fb17e96e095c4415318e91eb696beef5 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Tue, 10 Nov 2020 11:15:25 +0300 Subject: [PATCH] cleanup --- cmd/gh/main.go | 11 ++++------- internal/config/from_env.go | 8 ++++---- pkg/cmd/api/api.go | 4 ++-- pkg/cmd/root/help_topic.go | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/cmd/gh/main.go b/cmd/gh/main.go index e812feae4..539e109c9 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -136,14 +136,11 @@ func main() { cs := cmdFactory.IOStreams.ColorScheme() - // _, _, tokenPresent := config.AuthTokenFromEnv(ghinstance.OverridableDefault()) - // authCheckEnabled := !tokenPresent && cmd != nil && cmdutil.IsAuthCheckEnabled(cmd) - authCheckEnabled := cmd != nil && cmdutil.IsAuthCheckEnabled(cmd) - if authCheckEnabled && !cmdutil.CheckAuth(cfg) { + if cmd != nil && cmdutil.IsAuthCheckEnabled(cmd) && !cmdutil.CheckAuth(cfg) { fmt.Fprintln(stderr, cs.Bold("Welcome to GitHub CLI!")) fmt.Fprintln(stderr) fmt.Fprintln(stderr, "To authenticate, please run `gh auth login`.") - fmt.Fprintln(stderr, "You can also set the one of the oauth token environment variables, if preferred.") + fmt.Fprintln(stderr, "You can also set the one of the auth token environment variables, if preferred.") os.Exit(4) } @@ -246,8 +243,8 @@ func basicClient(currentVersion string) (*api.Client, error) { } opts = append(opts, api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", currentVersion))) - token, _, ok := config.AuthTokenFromEnv(ghinstance.Default()) - if !ok { + token, _, found := config.AuthTokenFromEnv(ghinstance.Default()) + if !found { if c, err := config.ParseDefaultConfig(); err == nil { token, _ = c.Get(ghinstance.Default(), "oauth_token") } diff --git a/internal/config/from_env.go b/internal/config/from_env.go index 2fb5f75fc..0522aa39c 100644 --- a/internal/config/from_env.go +++ b/internal/config/from_env.go @@ -45,8 +45,8 @@ func (c *envConfig) Get(hostname, key string) (string, error) { func (c *envConfig) GetWithSource(hostname, key string) (string, string, error) { if hostname != "" && key == "oauth_token" { - if value, name, found := AuthTokenFromEnv(hostname); found { - return value, name, nil + if token, env, found := AuthTokenFromEnv(hostname); found { + return token, env, nil } } @@ -55,8 +55,8 @@ func (c *envConfig) GetWithSource(hostname, key string) (string, string, error) func (c *envConfig) CheckWriteable(hostname, key string) error { if hostname != "" && key == "oauth_token" { - if _, name, found := AuthTokenFromEnv(hostname); found { - return fmt.Errorf("read-only token in %s cannot be modified", name) + if _, env, found := AuthTokenFromEnv(hostname); found { + return fmt.Errorf("read-only token in %s cannot be modified", env) } } diff --git a/pkg/cmd/api/api.go b/pkg/cmd/api/api.go index 11bc92766..16e61e7e1 100644 --- a/pkg/cmd/api/api.go +++ b/pkg/cmd/api/api.go @@ -119,9 +119,9 @@ original query accepts an '$endCursor: String' variable and that it fetches the `), Annotations: map[string]string{ "help:environment": heredoc.Doc(` - GH_TOKEN, GITHUB_TOKEN (in order of procedence): an authentication token for github.com API requests. + GH_TOKEN, GITHUB_TOKEN (in order of precedence): an authentication token for github.com API requests. - GH_ENTERPRISE_TOKEN, GITHUB_ENTERPRISE_TOKEN (in order of procedence): an authentication token for API requests to GitHub Enterprise. + GH_ENTERPRISE_TOKEN, GITHUB_ENTERPRISE_TOKEN (in order of precedence): an authentication token for API requests to GitHub Enterprise. GH_HOST: make the request to a GitHub host other than github.com. `), diff --git a/pkg/cmd/root/help_topic.go b/pkg/cmd/root/help_topic.go index 63bfa7ff7..c44bfca00 100644 --- a/pkg/cmd/root/help_topic.go +++ b/pkg/cmd/root/help_topic.go @@ -9,7 +9,7 @@ var HelpTopics = map[string]map[string]string{ "environment": { "short": "Environment variables that can be used with gh", "long": heredoc.Doc(` - GH_TOKEN, GITHUB_TOKEN (in order of procedence): an authentication token for github.com + GH_TOKEN, GITHUB_TOKEN (in order of precedence): an authentication token for github.com API requests. Setting this avoids being prompted to authenticate and takes precedence over previously stored credentials.