From 2860b393538b3e02796feb244f891745ccadf288 Mon Sep 17 00:00:00 2001 From: Zeev Manilovich Date: Wed, 2 Mar 2022 16:37:52 +0200 Subject: [PATCH] cmd/action: make env command public (#613) * cmd/action: extract env cmd * move init() func * remove var * global var and fix tests * gen --- cmd/action/env.go | 29 ++++++++++++++--------------- cmd/action/env_test.go | 6 ++---- doc/md/cli/reference.md | 4 ++-- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/cmd/action/env.go b/cmd/action/env.go index abcf3504616..231f025efea 100644 --- a/cmd/action/env.go +++ b/cmd/action/env.go @@ -13,29 +13,28 @@ import ( "github.com/spf13/cobra" ) -func newEnvCmd() *cobra.Command { - return &cobra.Command{ - Use: "env", - Short: "Print atlas environment variables.", - Long: "`atlas env`" + `prints atlas environment information. +// EnvCmd is the "atlas env" command. +var EnvCmd = &cobra.Command{ + Use: "env", + Short: "Print atlas environment variables.", + Long: `'atlas env' prints atlas environment information. Every set environment param will be printed in the form of NAME=VALUE. List of supported environment parameters: -* *ATLAS_NO_UPDATE_NOTIFIER*: On any command, the CLI will check for new releases using the GitHub API. +* ATLAS_NO_UPDATE_NOTIFIER: On any command, the CLI will check for new releases using the GitHub API. This check will happen at most once every 24 hours. To cancel this behavior, set the environment variable "ATLAS_NO_UPDATE_NOTIFIER".`, - Run: func(cmd *cobra.Command, args []string) { - keys := []string{update.AtlasNoUpdateNotifier} - for _, k := range keys { - if v, ok := os.LookupEnv(k); ok { - cmd.Println(fmt.Sprintf("%s=%s", k, v)) - } + Run: func(cmd *cobra.Command, args []string) { + keys := []string{update.AtlasNoUpdateNotifier} + for _, k := range keys { + if v, ok := os.LookupEnv(k); ok { + cmd.Println(fmt.Sprintf("%s=%s", k, v)) } - }, - } + } + }, } func init() { - RootCmd.AddCommand(newEnvCmd()) + RootCmd.AddCommand(EnvCmd) } diff --git a/cmd/action/env_test.go b/cmd/action/env_test.go index 4a138a055ff..d7d03f87f06 100644 --- a/cmd/action/env_test.go +++ b/cmd/action/env_test.go @@ -10,17 +10,15 @@ import ( ) func TestEnv(t *testing.T) { - cmd := newEnvCmd() - out, err := runCmd(cmd) + out, err := runCmd(RootCmd, "env") require.NoError(t, err) require.Empty(t, out) } func TestEnv_Set(t *testing.T) { - cmd := newEnvCmd() err := os.Setenv(update.AtlasNoUpdateNotifier, "test") require.NoError(t, err) - out, err := runCmd(cmd) + out, err := runCmd(RootCmd, "env") require.NoError(t, err) require.Equal(t, "ATLAS_NO_UPDATE_NOTIFIER=test\n", out) } diff --git a/doc/md/cli/reference.md b/doc/md/cli/reference.md index 3048865b139..69d824a45a7 100644 --- a/doc/md/cli/reference.md +++ b/doc/md/cli/reference.md @@ -36,12 +36,12 @@ atlas env ``` #### Details -`atlas env`prints atlas environment information. +'atlas env' prints atlas environment information. Every set environment param will be printed in the form of NAME=VALUE. List of supported environment parameters: -* *ATLAS_NO_UPDATE_NOTIFIER*: On any command, the CLI will check for new releases using the GitHub API. +* ATLAS_NO_UPDATE_NOTIFIER: On any command, the CLI will check for new releases using the GitHub API. This check will happen at most once every 24 hours. To cancel this behavior, set the environment variable "ATLAS_NO_UPDATE_NOTIFIER".