(cmd *cobra.Command)
| 206 | } |
| 207 | |
| 208 | func initializeConfig(cmd *cobra.Command) error { |
| 209 | v := viper.New() |
| 210 | v.SetDefault("Verbose", true) |
| 211 | // TODO add a file-based config |
| 212 | v.SetConfigName(config.ConfigFileBasename) |
| 213 | v.AddConfigPath(".") |
| 214 | if err := v.ReadInConfig(); err != nil { |
| 215 | if _, ok := err.(viper.ConfigFileNotFoundError); !ok { |
| 216 | return err |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | v.SetEnvPrefix(config.ViperEnvPrefix) |
| 221 | v.AutomaticEnv() |
| 222 | bindFlags(cmd, v) |
| 223 | |
| 224 | return nil |
| 225 | } |
| 226 | |
| 227 | // bindFlags binds cobra flags to viper environment variables |
| 228 | func bindFlags(cmd *cobra.Command, v *viper.Viper) { |
no test coverage detected