ppass handle debug flag

This commit is contained in:
2024-10-10 14:16:21 +02:00
parent a3f2a5ee6d
commit 817a14704b

View File

@@ -13,6 +13,7 @@ import (
var ( var (
dbPath = flag.String("db", "./db", "db file path") dbPath = flag.String("db", "./db", "db file path")
debug bool
) )
// Create the root command // Create the root command
@@ -342,6 +343,7 @@ var deleteCmd = &cobra.Command{
func init() { func init() {
rootCmd.PersistentFlags().String("db", "", "db path") rootCmd.PersistentFlags().String("db", "", "db path")
rootCmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug mode")
rootCmd.MarkPersistentFlagRequired("db") rootCmd.MarkPersistentFlagRequired("db")
peerCmd.AddCommand(addPeerCmd) peerCmd.AddCommand(addPeerCmd)
@@ -361,7 +363,7 @@ func init() {
} }
func main() { func main() {
InitLogger(false) cobra.OnInitialize(func() { InitLogger(debug) })
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
Logger.Error(err) Logger.Error(err)
os.Exit(1) os.Exit(1)