diff --git a/cmd/root.go b/cmd/root.go index 91de49c4..1416e3b7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -290,7 +290,11 @@ func setFlagsFromConfig() error { return err } - _ = viper.ReadInConfig() + err = viper.ReadInConfig() + if err != nil { + // attempt to write config file if it does not exist + _ = viper.SafeWriteConfigAs(configFile) + } return nil } diff --git a/internal/config/config.go b/internal/config/config.go index 2491747a..ec56a7df 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -32,7 +32,9 @@ type Config struct { func New(filename string, readFile ReadFile) (Config, error) { data, err := readFile(filename) if err != nil { - return Config{}, err + return Config{}, errors.NewError( + fmt.Sprintf("unable to open config file. The file or directory may not exist: %s", filename), + ) } var c Config