From bf93c72c923ed08599f9f10695c21d5cd43a7abb Mon Sep 17 00:00:00 2001 From: Mate Ory Date: Fri, 13 Nov 2020 08:16:05 +0100 Subject: [PATCH] cluster: don't bind current cluster id env var this made for example `banzai org select` saving the cluster id to config when executed in a banzai shell --- internal/cli/command/cluster/context/context.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/cli/command/cluster/context/context.go b/internal/cli/command/cluster/context/context.go index 37d19296..fbc4253a 100644 --- a/internal/cli/command/cluster/context/context.go +++ b/internal/cli/command/cluster/context/context.go @@ -17,6 +17,7 @@ package clustercontext import ( "context" "fmt" + "os" "emperror.dev/errors" "github.com/AlecAivazis/survey/v2" @@ -48,7 +49,6 @@ func NewClusterContext(cmd *cobra.Command, banzaiCli cli.Cli, verb string) Conte flags := cmd.Flags() flags.Int32Var(&ctx.id, "cluster", 0, fmt.Sprintf("ID of cluster to %s", verb)) - viper.BindEnv(clusterIdKey, "BANZAI_CURRENT_CLUSTER_ID") flags.StringVar(&ctx.name, "cluster-name", "", fmt.Sprintf("Name of cluster to %s", verb)) return &ctx @@ -79,7 +79,12 @@ func (c *clusterContext) Init(args ...string) error { return errors.New("invalid number of arguments") } - if c.name == "" && c.id == 0 { + if id := os.Getenv("BANZAI_CURRENT_CLUSTER_ID"); id != "" { + _, err := fmt.Sscanf(id, "%d", &c.id) + if err != nil { + return errors.WrapIff(err, "invalid BANZAI_CURRENT_CLUSTER_ID=%q env var", id) + } + } else if c.name == "" && c.id == 0 { c.id = viper.GetInt32(clusterIdKey) }