File tree 2 files changed +13
-6
lines changed
2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ func saveConfiguration() error {
51
51
// use viper to save the configuration
52
52
viper .Set ("server" , rootConfig .Server )
53
53
viper .Set ("token" , rootConfig .Token )
54
- if err := viper .SafeWriteConfig (); err != nil {
54
+ if err := viper .WriteConfig (); err != nil {
55
55
color .Red ("Failed to configure ADC" )
56
56
return err
57
57
}
Original file line number Diff line number Diff line change @@ -55,15 +55,22 @@ func Execute() {
55
55
}
56
56
57
57
func initConfig () {
58
- if cfgFile != "" {
59
- viper .SetConfigFile (cfgFile )
60
- } else {
61
- // set default config file $HOME/.adc.yaml
62
- viper .SetConfigFile ("$HOME/.adc.yaml" )
58
+ if cfgFile == "" {
59
+ cfgFile = "$HOME/.adc.yaml"
63
60
}
61
+ viper .SetConfigFile (cfgFile )
64
62
viper .SetConfigName (".adc" )
65
63
viper .SetConfigType ("yaml" )
66
64
viper .AddConfigPath ("$HOME/" )
65
+
66
+ if _ , err := os .Stat (os .ExpandEnv (cfgFile )); err != nil {
67
+ color .Yellow ("Config file not found at %s. Creating..." , cfgFile )
68
+ _ , err := os .Create (os .ExpandEnv (cfgFile ))
69
+ if err != nil {
70
+ color .Red ("Failed to initialize configuration file: %s" , err )
71
+ }
72
+ }
73
+
67
74
err := viper .ReadInConfig ()
68
75
if err != nil {
69
76
color .Red ("Failed to read configuration file, please run `adc configure` first to configure ADC." )
You can’t perform that action at this time.
0 commit comments