Fix --config flag
authorMikael Berthe <mikael@lilotux.net>
Sat, 21 Oct 2017 19:06:26 +0200
changeset 171 611c211534d0
parent 170 9c731a8b75ed
child 172 0d651f070319
Fix --config flag If viper.SetConfigName is called after viper.SetConfigFile, the file setting is erased...
cmd/root.go
--- a/cmd/root.go	Sat Oct 21 19:05:11 2017 +0200
+++ b/cmd/root.go	Sat Oct 21 19:06:26 2017 +0200
@@ -170,9 +170,6 @@
 	if cfgFile == "/dev/null" {
 		return
 	}
-	if cfgFile != "" { // enable ability to specify config file via flag
-		viper.SetConfigFile(cfgFile)
-	}
 
 	viper.SetConfigName(AppName) // name of config file (without extension)
 	viper.AddConfigPath("$HOME/.config/" + AppName)
@@ -182,6 +179,9 @@
 	viper.SetEnvPrefix(AppName)
 	viper.AutomaticEnv()
 
+	// Enable ability to specify config file via flag
+	viper.SetConfigFile(cfgFile)
+
 	// If a config file is found, read it in.
 	err := viper.ReadInConfig()
 	if err != nil {