Skip to content

Commit

Permalink
Use CountVarP instead of BoolVarP to allow shorthand -vv for loglevel…
Browse files Browse the repository at this point in the history
… debug
  • Loading branch information
ma-hartma committed Nov 3, 2021
1 parent d2c7d6e commit e3c7ac8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/knoxite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type GlobalOptions struct {
Alias string
Password string
ConfigURL string
Verbose bool
Verbose int
LogLevel string
}

Expand Down Expand Up @@ -74,7 +74,7 @@ func main() {
RootCmd.PersistentFlags().StringVar(&globalOpts.Password, "password", "", "Password to use for data encryption")
RootCmd.PersistentFlags().StringVarP(&globalOpts.ConfigURL, "configURL", "C", config.DefaultPath(), "Path to the configuration file")
RootCmd.PersistentFlags().StringVar(&globalOpts.LogLevel, "loglevel", "Print", "Verbose output. Possible levels are Debug, Info, Warning and Fatal")
RootCmd.PersistentFlags().BoolVarP(&globalOpts.Verbose, "verbose", "v", false, "Verbose output on log level Info. Use --loglevel to choose between Debug, Info, Warning and Fatal")
RootCmd.PersistentFlags().CountVarP(&globalOpts.Verbose, "verbose", "v", "Verbose output on log level Info (-v) or Debug (-vv). Use --loglevel to choose between Debug, Info, Warning and Fatal")

globalOpts.Repo = os.Getenv("KNOXITE_REPOSITORY")
globalOpts.Password = os.Getenv("KNOXITE_PASSWORD")
Expand All @@ -100,8 +100,11 @@ func init() {
}

func initLogger() {
if globalOpts.Verbose {
switch globalOpts.Verbose {
case 1:
globalOpts.LogLevel = "Info"
case 2:
globalOpts.LogLevel = "Debug"
}

logLevel, err := utils.LogLevelFromString(globalOpts.LogLevel)
Expand Down

0 comments on commit e3c7ac8

Please sign in to comment.