Archived
1
0

Adds flags for log levels

This commit is contained in:
Jip J. Dekker 2016-03-19 21:35:06 +01:00
parent 9ad93eb620
commit 7d226ca520

View File

@ -17,9 +17,15 @@ package cmd
import (
"os"
log "github.com/Sirupsen/logrus"
"github.com/spf13/cobra"
)
var (
veryVerbose bool
verbose bool
)
// This represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "ponder",
@ -42,12 +48,18 @@ func Execute() {
}
func init() {
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags, which, if defined here,
// will be global for your application.
RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Verbose output of application events")
RootCmd.PersistentFlags().BoolVar(&veryVerbose, "vv", false, "Debug output of application events")
// RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.ponder.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
// RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
setLogLevel()
}
func setLogLevel() {
if veryVerbose {
log.SetLevel(log.DebugLevel)
} else if verbose {
log.SetLevel(log.InfoLevel)
} else {
log.SetLevel(log.WarnLevel)
}
}