mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
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:
committed by
Cuong Manh Le
parent
7bf231643b
commit
411e23ecfe
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user