Skip to content

Commit

Permalink
add config file generation for writable config
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rk committed Mar 8, 2024
1 parent a9624e4 commit 6a884fc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/global/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,18 @@ func (c *config) Init() {
// assuming the provided configFile is read-only
c.writableConfig = viper.New()
if err := c.loadConfig(c.writableConfig, nil); err != nil {
output.Fail(err)
if isUnknownError(err) {
output.Failf("Error reading config file: %s (%v)", c.writableConfig.ConfigFileUsed(), err.Error())
}
err = generateDefaultConfig()
if err != nil {
output.Failf("Error generating default config file: %v", err.Error())
}

// We read generated config now
if err = c.loadConfig(c.writableConfig, configFile); err != nil {
output.Failf("Error reading config file: %s (%v)", viper.ConfigFileUsed(), err.Error())
}
}
} else {
c.writableConfig = viper.GetViper()
Expand Down

0 comments on commit 6a884fc

Please sign in to comment.