cmd/root.go
changeset 65 0491cc43911e
parent 55 e9df533a1c4f
child 66 43d43c8b53aa
equal deleted inserted replaced
64:0a3663970622 65:0491cc43911e
   181 	// Read in environment variables that match, with a prefix
   181 	// Read in environment variables that match, with a prefix
   182 	viper.SetEnvPrefix(AppName)
   182 	viper.SetEnvPrefix(AppName)
   183 	viper.AutomaticEnv()
   183 	viper.AutomaticEnv()
   184 
   184 
   185 	// If a config file is found, read it in.
   185 	// If a config file is found, read it in.
   186 	if err := viper.ReadInConfig(); viper.GetBool("verbose") && err == nil {
   186 	err := viper.ReadInConfig()
       
   187 	if err != nil {
       
   188 		if cfgFile != "" {
       
   189 			errPrint("Error: cannot read configuration file '%s'", cfgFile)
       
   190 			os.Exit(-1)
       
   191 		}
       
   192 	} else if viper.GetBool("verbose") {
   187 		errPrint("Using config file: %s", viper.ConfigFileUsed())
   193 		errPrint("Using config file: %s", viper.ConfigFileUsed())
   188 	}
   194 	}
   189 }
   195 }
   190 
   196 
   191 // getOutputFormat return the requested output format, defaulting to "plain".
   197 // getOutputFormat return the requested output format, defaulting to "plain".