mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
when using --verbose set the JIRA_DEBUG environment variable so custom-commands can auto enable verbose output
This commit is contained in:
+19
-6
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user