From 478338fb0b2aa29c08ef5eed7efa0d40e12214f6 Mon Sep 17 00:00:00 2001 From: Fabian Siegel Date: Thu, 13 May 2021 14:15:30 +0200 Subject: [PATCH] gh-7 only print debug logs if debug flag is set --- cmd/commands/pr/create/create.go | 2 +- cmd/root.go | 1 + util/logging/logging.go | 12 ++++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/commands/pr/create/create.go b/cmd/commands/pr/create/create.go index 598286b..6af7c75 100644 --- a/cmd/commands/pr/create/create.go +++ b/cmd/commands/pr/create/create.go @@ -440,7 +440,7 @@ func manageReviewers(bbrepo *bbgit.BitbucketRepo, c *client.Client, currentUser nameToUUID[name] = rev } if len(listOfNames) == 0 { - logging.Warning("No reviwers to add available") + logging.Warning("No reviewers to add available") continue } var addedReviewers []string diff --git a/cmd/root.go b/cmd/root.go index 1d845bb..67c5271 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -85,6 +85,7 @@ func init() { rootCmd.PersistentFlags().StringVar(&username, "username", "", "username") rootCmd.PersistentFlags().StringVar(&password, "password", "", "app password") rootCmd.PersistentFlags().StringVar(&remoteName, "remote", "origin", "if you are in a repository and don't want to interact with the default origin, you can change it") + rootCmd.PersistentFlags().BoolVar(&logging.PrintDebugLogs, "debug", false, "enabling this flag allows debug logs to be printed") err := viper.BindPFlag("username", rootCmd.PersistentFlags().Lookup("username")) if err != nil { diff --git a/util/logging/logging.go b/util/logging/logging.go index fb3219a..e2e61c3 100644 --- a/util/logging/logging.go +++ b/util/logging/logging.go @@ -6,12 +6,20 @@ import ( "github.com/logrusorgru/aurora" ) +var ( + PrintDebugLogs = false +) + func Debug(message ...interface{}) { - fmt.Printf("%s%s\n", aurora.BgCyan(":: "+aurora.Bold("DEBUG: ").String()), fmt.Sprint(message...)) + if PrintDebugLogs { + fmt.Printf("%s%s\n", aurora.BgCyan(":: "+aurora.Bold("DEBUG: ").String()), fmt.Sprint(message...)) + } } func Debugf(message ...interface{}) { - fmt.Printf("%s%s\n", aurora.BgCyan(":: "+aurora.Bold("DEBUG: ").String()), fmt.Sprintf(message[0].(string), message[1:]...)) + if PrintDebugLogs { + fmt.Printf("%s%s\n", aurora.BgCyan(":: "+aurora.Bold("DEBUG: ").String()), fmt.Sprintf(message[0].(string), message[1:]...)) + } } func Error(message ...interface{}) {