Skip to content

Commit

Permalink
when using --verbose set the JIRA_DEBUG environment variable so custo…
Browse files Browse the repository at this point in the history
…m-commands can auto enable verbose output
  • Loading branch information
coryb committed Aug 31, 2017
1 parent ec0858b commit da9a2b2
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cmd/jira/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"regexp"
"runtime/debug"
"strconv"

"github.com/coryb/figtree"
"github.com/coryb/kingpeon"
Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand Down

0 comments on commit da9a2b2

Please sign in to comment.