Skip to content

Commit bf93c72

Browse files
author
Mate Ory
committed
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
1 parent b645ea9 commit bf93c72

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

internal/cli/command/cluster/context/context.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package clustercontext
1717
import (
1818
"context"
1919
"fmt"
20+
"os"
2021

2122
"emperror.dev/errors"
2223
"github.com/AlecAivazis/survey/v2"
@@ -48,7 +49,6 @@ func NewClusterContext(cmd *cobra.Command, banzaiCli cli.Cli, verb string) Conte
4849
flags := cmd.Flags()
4950

5051
flags.Int32Var(&ctx.id, "cluster", 0, fmt.Sprintf("ID of cluster to %s", verb))
51-
viper.BindEnv(clusterIdKey, "BANZAI_CURRENT_CLUSTER_ID")
5252
flags.StringVar(&ctx.name, "cluster-name", "", fmt.Sprintf("Name of cluster to %s", verb))
5353

5454
return &ctx
@@ -79,7 +79,12 @@ func (c *clusterContext) Init(args ...string) error {
7979
return errors.New("invalid number of arguments")
8080
}
8181

82-
if c.name == "" && c.id == 0 {
82+
if id := os.Getenv("BANZAI_CURRENT_CLUSTER_ID"); id != "" {
83+
_, err := fmt.Sscanf(id, "%d", &c.id)
84+
if err != nil {
85+
return errors.WrapIff(err, "invalid BANZAI_CURRENT_CLUSTER_ID=%q env var", id)
86+
}
87+
} else if c.name == "" && c.id == 0 {
8388
c.id = viper.GetInt32(clusterIdKey)
8489
}
8590

0 commit comments

Comments
 (0)