From da9a2b2b90799a2482061dde7673e2d8aed028d8 Mon Sep 17 00:00:00 2001 From: Cory Bennett Date: Thu, 31 Aug 2017 15:09:32 -0700 Subject: [PATCH] when using --verbose set the JIRA_DEBUG environment variable so custom-commands can auto enable verbose output --- cmd/jira/main.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/cmd/jira/main.go b/cmd/jira/main.go index 243f1d18..a11e5fab 100644 --- a/cmd/jira/main.go +++ b/cmd/jira/main.go @@ -7,6 +7,7 @@ import ( "path/filepath" "regexp" "runtime/debug" + "strconv" "github.com/coryb/figtree" "github.com/coryb/kingpeon" @@ -34,6 +35,14 @@ func handleExit() { } } +func increaseLogLevel(verbosity int) { + logging.SetLevel(logging.GetLevel("")+logging.Level(verbosity), "") + if logging.GetLevel("") > logging.DEBUG { + oreo.TraceRequestBody = true + oreo.TraceResponseBody = true + } +} + func main() { defer handleExit() logBackend := logging.NewLogBackend(os.Stderr, "", 0) @@ -59,14 +68,18 @@ func main() { panic(jiracli.Exit{Code: 0}) }) + var verbosity int app.Flag("verbose", "Increase verbosity for debugging").Short('v').PreAction(func(_ *kingpin.ParseContext) error { - logging.SetLevel(logging.GetLevel("")+1, "") - if logging.GetLevel("") > logging.DEBUG { - oreo.TraceRequestBody = true - oreo.TraceResponseBody = true - } + os.Setenv("JIRA_DEBUG", fmt.Sprintf("%s", verbosity)) + increaseLogLevel(1) return nil - }).Counter() + }).CounterVar(&verbosity) + + if os.Getenv("JIRA_DEBUG") != "" { + if verbosity, err := strconv.Atoi(os.Getenv("JIRA_DEBUG")); err == nil { + increaseLogLevel(verbosity) + } + } fig := figtree.NewFigTree() fig.EnvPrefix = "JIRA"