Skip to content

Commit

Permalink
Fix WriteConfig (spf13#430, spf13#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
yann-soubeyrand committed Jul 14, 2020
1 parent 13df721 commit 8f277a4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1407,11 +1407,10 @@ func (v *Viper) MergeConfigMap(cfg map[string]interface{}) error {
// WriteConfig writes the current configuration to a file.
func WriteConfig() error { return v.WriteConfig() }
func (v *Viper) WriteConfig() error {
filename, err := v.getConfigFile()
if err != nil {
return err
if len(v.configPaths) < 1 {
return errors.New("missing configuration for 'configPath'")
}
return v.writeConfig(filename, true)
return v.WriteConfigAs(filepath.Join(v.configPaths[0], v.configName+"."+v.configType))
}

// SafeWriteConfig writes current configuration to file only if the file does not exist.
Expand Down

0 comments on commit 8f277a4

Please sign in to comment.