diff --git a/cmd/diagnostic.go b/cmd/diagnostic.go index 64dfda99c..53e53f290 100644 --- a/cmd/diagnostic.go +++ b/cmd/diagnostic.go @@ -28,5 +28,5 @@ func diagnostic(cmd *cobra.Command, args []string) { Logger.Infoln("OK, got a token.") } - Logger.Infof("Verbose mode: %v\n", Config.Verbose) + Logger.Infof("Verbose mode: %v\n", viper.GetBool("verbose")) } diff --git a/cmd/root.go b/cmd/root.go index 294e119a7..2abbdce70 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -26,8 +26,7 @@ var Logger *logger.Logger // Config is the current configuration available to all commands in `cmd` package. var Config = &config.Config{ - Verbose: false, - Name: "cli", + Name: "cli", } var rootCmd = &cobra.Command{ @@ -44,7 +43,7 @@ func addCommands() { func init() { cobra.OnInitialize(setup) - rootCmd.PersistentFlags().BoolVarP(&Config.Verbose, "verbose", "v", false, "Enable verbose logging.") + rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose logging.") rootCmd.PersistentFlags().StringVarP(&Config.File, "config", "c", "", "config file (default is $HOME/.circleci/cli.yml)") rootCmd.PersistentFlags().StringP("endpoint", "e", "https://circleci.com/graphql", "the endpoint of your CircleCI GraphQL API") @@ -52,10 +51,18 @@ func init() { Logger.FatalOnError("Error binding endpoint flag", viper.BindPFlag("endpoint", rootCmd.PersistentFlags().Lookup("endpoint"))) Logger.FatalOnError("Error binding token flag", viper.BindPFlag("token", rootCmd.PersistentFlags().Lookup("token"))) + + err := viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose")) + + if err != nil { + panic(err) + } + + addCommands() } func setup() { - Logger = logger.NewLogger(Config.Verbose) + Logger = logger.NewLogger(viper.GetBool("verbose")) Logger.FatalOnError( "Failed to setup configuration: ", Config.Init(), diff --git a/config/config.go b/config/config.go index ce2bfe971..d9ea89986 100644 --- a/config/config.go +++ b/config/config.go @@ -9,9 +9,8 @@ import ( // Config is a struct of the current configuration available at runtime. type Config struct { - Verbose bool - File string - Name string + File string + Name string } // Init is called on initialize of the root command.