mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
Set the defaults BEFORE considering a --config CLI argument
This commit is contained in:
parent
9c28e4bbd7
commit
3a67b686d1
1 changed files with 3 additions and 2 deletions
|
@ -57,12 +57,13 @@ func init() {
|
||||||
|
|
||||||
// Read in config file and ENV variables if set.
|
// Read in config file and ENV variables if set.
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
|
viper.SetConfigName(".cobra") // name of config file (without extension)
|
||||||
|
viper.AddConfigPath("$HOME") // adding home directory as first search path
|
||||||
|
|
||||||
if cfgFile != "" { // enable ability to specify config file via flag
|
if cfgFile != "" { // enable ability to specify config file via flag
|
||||||
viper.SetConfigFile(cfgFile)
|
viper.SetConfigFile(cfgFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
viper.SetConfigName(".cobra") // name of config file (without extension)
|
|
||||||
viper.AddConfigPath("$HOME") // adding home directory as first search path
|
|
||||||
viper.AutomaticEnv() // read in environment variables that match
|
viper.AutomaticEnv() // read in environment variables that match
|
||||||
|
|
||||||
// If a config file is found, read it in.
|
// If a config file is found, read it in.
|
||||||
|
|
Loading…
Reference in a new issue