From 5e91d28485fb3c3c835104afd61fdbab4d647023 Mon Sep 17 00:00:00 2001 From: "wuhua.ck" Date: Fri, 4 Mar 2022 14:43:18 +0800 Subject: [PATCH 1/2] check file exist before write --- cli/cmd/root.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/cmd/root.go b/cli/cmd/root.go index dbe2ef6237..50acdacf67 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -75,11 +75,12 @@ func initConfig() { viper.AddConfigPath(home) viper.SetConfigType("yaml") viper.SetConfigName(".kuberay") - viper.SetDefault("endpoint", fmt.Sprintf("%s:%s", cmdutil.DefaultRpcAddress, cmdutil.DefaultRpcPort)) // Do not write to file system if it already exists if err := viper.SafeWriteConfig(); err != nil { - klog.Fatal(err) + if _, ok := err.(viper.ConfigFileAlreadyExistsError); !ok { + klog.Fatal(err) + } } } From f122cd8cbec8275fea053f27212e4b0390ec07ab Mon Sep 17 00:00:00 2001 From: "wuhua.ck" Date: Fri, 4 Mar 2022 15:00:59 +0800 Subject: [PATCH 2/2] fix --- cli/cmd/root.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/cmd/root.go b/cli/cmd/root.go index 50acdacf67..c57057f8e3 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -75,6 +75,7 @@ func initConfig() { viper.AddConfigPath(home) viper.SetConfigType("yaml") viper.SetConfigName(".kuberay") + viper.SetDefault("endpoint", fmt.Sprintf("%s:%s", cmdutil.DefaultRpcAddress, cmdutil.DefaultRpcPort)) // Do not write to file system if it already exists if err := viper.SafeWriteConfig(); err != nil {