Skip to content

Commit 8310e9b

Browse files
committed
Add verbose and debug flags
1 parent 21b353d commit 8310e9b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

commands/app.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const (
1414
var (
1515
VERSION string
1616
GITSHA1 string
17+
18+
boolVerbose, boolDebug bool
1719
)
1820

1921
var app = &cobra.Command{
@@ -26,12 +28,23 @@ var app = &cobra.Command{
2628
}
2729

2830
func init() {
31+
flags := app.PersistentFlags()
32+
flags.BoolVarP(&boolVerbose, "verbose", "V", false, "Print verbose messages")
33+
flags.BoolVarP(&boolDebug, "debug", "D", false, "Print debug messages")
34+
2935
cobra.OnInitialize(Initialize)
3036
}
3137

3238
func Initialize() {
3339
log.SetOutput(os.Stderr)
3440
log.SetLevel(log.WarnLevel)
41+
42+
if boolVerbose {
43+
log.SetLevel(log.InfoLevel)
44+
}
45+
if boolDebug {
46+
log.SetLevel(log.DebugLevel)
47+
}
3548
}
3649

3750
func Execute() {

0 commit comments

Comments
 (0)