Skip to content

Commit

Permalink
Remove the verbose field, replace with direct calls to Viper
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomorain committed Jun 13, 2018
1 parent e518c58 commit d4a2673
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
15 changes: 11 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -44,18 +43,26 @@ 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")
rootCmd.PersistentFlags().StringP("token", "t", "", "your token for using CircleCI")

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(),
Expand Down
5 changes: 2 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d4a2673

Please sign in to comment.