cmd/ctrld: fix missing content for default config

When writing default config file, the content must be marshalled to the
config object first before writing to disk.

While at it, also use full path for default config file to make it clear
to the user where the config is written.
This commit is contained in:
Cuong Manh Le
2023-04-27 00:41:09 +07:00
committed by Cuong Manh Le
parent 7bf231643b
commit 411e23ecfe

View File

@@ -608,10 +608,17 @@ func readConfigFile(writeDefaultConfig bool) bool {
// If error is viper.ConfigFileNotFoundError, write default config.
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
if err := v.Unmarshal(&cfg); err != nil {
log.Fatalf("failed to unmarshal default config: %v", err)
}
if err := writeConfigFile(); err != nil {
log.Fatalf("failed to write default config file: %v", err)
} else {
log.Println("writing default config file to: " + defaultConfigFile)
fp, err := filepath.Abs(defaultConfigFile)
if err != nil {
log.Fatalf("failed to get default config file path: %v", err)
}
log.Println("writing default config file to: " + fp)
}
defaultConfigWritten = true
return false