The new WriteConfig function ends up calling findConfigFile, which in turn checks whether the file exists. If it doesn't then it returns an error, which stops the config being written.
I had similar issue too and filed as #430 and right now my workaround is like this,
if err := viper.SafeWriteConfigAs(configPath); err != nil {
if os.IsNotExist(err) {
err = viper.WriteConfigAs(configPath)
}
}
I'm just hoping there is a better solution.
Use WriteConfigAs which creates the file before writing.
I got same issue.
I think WriteConfig should create configfile as same as WriteConfigAs if the file does not exist
Most helpful comment
I got same issue.
I think WriteConfig should create configfile as same as WriteConfigAs if the file does not exist