(v *viper.Viper)
| 62 | } |
| 63 | |
| 64 | func Setup(v *viper.Viper) error { |
| 65 | setDefaults(v) |
| 66 | if err := bindEnvironment(v); err != nil { |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | configPath, err := getConfigPath() |
| 71 | if err == nil { |
| 72 | SetupConfigFile(v, configPath) |
| 73 | if err := v.ReadInConfig(); err != nil { |
| 74 | if _, ok := err.(viper.ConfigFileNotFoundError); ok { |
| 75 | // Do nothing, config file will be created on `config set` cmd |
| 76 | // This is to avoid issues with CI tools that may not have access |
| 77 | // to the file system |
| 78 | } else { |
| 79 | // Config file was found but something is wrong |
| 80 | // we can recover and run with no config |
| 81 | fmt.Println("Error reading config file: %w", err) |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | // if we can't get the configPath, then everything will just be defaulted |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | // EnsureConfigPath works out the config path, then creates the directory to make sure that it exists |
| 90 | func EnsureConfigPath() (string, error) { |
no test coverage detected