Skip to content

Commit

Permalink
Add verbose flag to enable debug logs (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Lopez authored Sep 25, 2018
1 parent 14d6415 commit 0e697fa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -11,11 +12,22 @@ var (
)

func init() {
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Use this to enable verbose mode")
}

var rootCmd = &cobra.Command{
Use: "blessclient",
Short: "",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
verbose, err := cmd.Flags().GetBool("verbose")
if err != nil {
return errors.Wrap(err, "Missing verbose flag")
}
if verbose {
log.SetLevel(log.DebugLevel)
}
return nil
},
}

// Execute executes the command
Expand Down

0 comments on commit 0e697fa

Please sign in to comment.