wifictld-analyzer/cmd/root.go

41 lines
954 B
Go

package cmd
import (
"github.com/bdlm/log"
"github.com/spf13/cobra"
)
var (
debug bool
timestamps bool
)
// RootCMD represents the base command when called without any subcommands
var RootCMD = &cobra.Command{
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.
// This is called by main.main(). It only needs to happen once to the RootCMD.
func Execute() {
if err := RootCMD.Execute(); err != nil {
log.Error(err)
}
}
func init() {
cobra.OnInitialize(func() {
if debug {
log.SetLevel(log.DebugLevel)
}
log.SetFormatter(&log.TextFormatter{
DisableTimestamp: timestamps,
})
log.Debug("show debug")
})
RootCMD.PersistentFlags().BoolVar(&debug, "v", false, "show debug log")
RootCMD.PersistentFlags().BoolVar(&timestamps, "timestamps", false, "Enables timestamps for log output")
}