wifictld-analyzer/cmd/root.go

41 lines
954 B
Go
Raw Normal View History

2018-06-02 01:00:54 +02:00
package cmd
import (
2019-02-28 16:24:29 +01:00
"github.com/bdlm/log"
2018-06-02 01:00:54 +02:00
"github.com/spf13/cobra"
)
2019-03-01 10:54:19 +01:00
var (
debug bool
timestamps bool
)
2018-06-02 01:00:54 +02:00
2019-03-01 10:54:19 +01:00
// RootCMD represents the base command when called without any subcommands
var RootCMD = &cobra.Command{
2018-06-02 01:00:54 +02:00
Use: "analyzer",
Short: "wifictld analyzer",
Long: `capture wifictld traffic and display thus`,
}
// Execute adds all child commands to the root command and sets flags appropriately.
2019-03-01 10:54:19 +01:00
// This is called by main.main(). It only needs to happen once to the RootCMD.
2018-06-02 01:00:54 +02:00
func Execute() {
2019-03-01 10:54:19 +01:00
if err := RootCMD.Execute(); err != nil {
2018-06-02 01:00:54 +02:00
log.Error(err)
}
}
func init() {
cobra.OnInitialize(func() {
if debug {
log.SetLevel(log.DebugLevel)
}
2019-03-01 10:54:19 +01:00
log.SetFormatter(&log.TextFormatter{
DisableTimestamp: timestamps,
})
2018-06-02 01:00:54 +02:00
log.Debug("show debug")
})
2019-03-01 10:54:19 +01:00
RootCMD.PersistentFlags().BoolVar(&debug, "v", false, "show debug log")
RootCMD.PersistentFlags().BoolVar(&timestamps, "timestamps", false, "Enables timestamps for log output")
2018-06-02 01:00:54 +02:00
}