diff --git a/.github/workflows/e2e-test.yaml b/.github/workflows/e2e-test.yaml index 6b97ed8b..fe645f15 100644 --- a/.github/workflows/e2e-test.yaml +++ b/.github/workflows/e2e-test.yaml @@ -93,5 +93,12 @@ jobs: echo "********************************************************************************" echo "Running kubecm global flag --config..." echo "********************************************************************************" - bin/kubecm s kind-3rd-kind --config merge.config - bin/kubecm list --config merge.config + bin/kubecm s kind-2nd-kind --config merge.config + echo "********************************************************************************" + echo "Running kubecm list from env KUBECONFIG..." + echo "********************************************************************************" + echo "default config" + bin/kubecm ls + echo "set env" + export KUBECONFIG="$PWD/multi.config" + bin/kubecm s kind-3rd-kind diff --git a/cmd/root.go b/cmd/root.go index 6a3e4b0d..49d2d5f1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -61,9 +61,13 @@ func NewCli() *Cli { } func (cli *Cli) setFlags() { - kubeconfig := flag.String("kubeconfig", filepath.Join(homeDir(), ".kube", "config"), "(optional) absolute path to the kubeconfig file") + // get env KUBECONFIG + kubeconfig := os.Getenv("KUBECONFIG") + if kubeconfig == "" { + kubeconfig = filepath.Join(homeDir(), ".kube", "config") + } flags := cli.rootCmd.PersistentFlags() - flags.StringVar(&cfgFile, "config", *kubeconfig, "path of kubeconfig") + flags.StringVar(&cfgFile, "config", kubeconfig, "path of kubeconfig") flags.IntVarP(&uiSize, "ui-size", "u", 4, "number of list items to show in menu at once") flags.BoolVarP(&silenceTable, "silence-table", "s", false, "enable/disable output of context table on successful config update") flags.BoolVarP(&macNotify, "mac-notify", "m", false, "enable to display Mac notification banner") diff --git a/cmd/utils.go b/cmd/utils.go index 9b2e1cea..546a729f 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -447,7 +447,8 @@ func CheckAndTransformFilePath(path string) (string, error) { if strings.HasPrefix(path, "~/") { path = filepath.Join(homeDir(), path[2:]) } - _, err := os.Stat(path) //os.Stat获取文件信息 + // read files info + _, err := os.Stat(path) if err != nil { return "", err }