when using --verbose set the JIRA_DEBUG environment variable so custom-commands can auto enable verbose output

This commit is contained in:
Cory Bennett
2017-08-31 15:09:32 -07:00
parent ec0858b09e
commit da9a2b2b90
+19 -6
View File
@@ -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"