Skip to content

Commit

Permalink
env: support variables unsetting (#332)
Browse files Browse the repository at this point in the history
This change adds a new flag `-u|--unset` to the `exo env` command,
allowing removal of the environment variables set by the `exo env`
command.
  • Loading branch information
falzm authored Apr 19, 2021
1 parent 1798b55 commit 9538542
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ import (
"github.com/spf13/cobra"
)

var envCmd = &cobra.Command{
Use: "env",
Hidden: true,
Run: func(cmd *cobra.Command, _ []string) {
vars := map[string]string{
"EXOSCALE_API_KEY": gCurrentAccount.Key,
"EXOSCALE_API_SECRET": gCurrentAccount.Secret,
"EXOSCALE_API_ENDPOINT": gCurrentAccount.Endpoint,
"EXOSCALE_API_ENVIRONMENT": gCurrentAccount.Environment,
}

unset, _ := cmd.Flags().GetBool("unset")

for k, v := range vars {
if unset {
fmt.Printf("unset %s\n", k)
} else {
fmt.Printf("export %s=%q\n", k, v)
}
}
},
}

func init() {
RootCmd.AddCommand(&cobra.Command{
Use: "environment",
Expand All @@ -20,17 +43,10 @@ variables supported:
Note: to override the current profile API credentials, *both* EXOSCALE_API_KEY
and EXOSCALE_API_SECRET variables have to be set.
`},
`,
},
)

RootCmd.AddCommand(&cobra.Command{
Use: "env",
Hidden: true,
Run: func(_ *cobra.Command, _ []string) {
fmt.Printf("export EXOSCALE_API_KEY=%q\n", gCurrentAccount.Key)
fmt.Printf("export EXOSCALE_API_SECRET=%q\n", gCurrentAccount.Secret)
fmt.Printf("export EXOSCALE_API_ENDPOINT=%q\n", gCurrentAccount.Endpoint)
fmt.Printf("export EXOSCALE_API_ENVIRONMENT=%q\n", gCurrentAccount.Environment)
},
})
envCmd.Flags().BoolP("unset", "u", false, "unset EXOSCALE_* environment variables")
RootCmd.AddCommand(envCmd)
}

0 comments on commit 9538542

Please sign in to comment.