Skip to content

Commit

Permalink
cmd/action: make env command public (#613)
Browse files Browse the repository at this point in the history
* cmd/action: extract env cmd

* move init() func

* remove var

* global var and fix tests

* gen
  • Loading branch information
zeevmoney authored Mar 2, 2022
1 parent 9a09b9e commit 2860b39
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
29 changes: 14 additions & 15 deletions cmd/action/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 2 additions & 4 deletions cmd/action/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions doc/md/cli/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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".

Expand Down

0 comments on commit 2860b39

Please sign in to comment.