From a7a96310e0bfd3c95caf913d63f6429415809507 Mon Sep 17 00:00:00 2001 From: DLDInternet Date: Tue, 27 Sep 2016 19:45:23 -0400 Subject: [PATCH] Set the defaults BEFORE considering a --config CLI argument --- cobra/cmd/root.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cobra/cmd/root.go b/cobra/cmd/root.go index 065c8bf4..78602fa8 100644 --- a/cobra/cmd/root.go +++ b/cobra/cmd/root.go @@ -57,12 +57,12 @@ func init() { // Read in config file and ENV variables if set. func initConfig() { - if cfgFile != "" { // enable ability to specify config file via flag + 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 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 // If a config file is found, read it in.