package cmd import ( "esway/internal/opt" "github.com/loveuer/nf/nft/log" "github.com/spf13/cobra" ) var rootCommand = &cobra.Command{ Use: "esway", PersistentPreRun: func(cmd *cobra.Command, args []string) { if opt.Cfg.Debug { log.SetLogLevel(log.LogLevelDebug) } }, RunE: func(cmd *cobra.Command, args []string) error { return execute(cmd.Context()) }, } func initRoot(cmds ...*cobra.Command) { rootCommand.PersistentFlags().BoolVar(&opt.Cfg.Debug, "debug", false, "debug mode") rootCommand.PersistentFlags().StringVarP(&opt.Cfg.Config, "config", "c", "etc/config.json", "config json file path") rootCommand.AddCommand(cmds...) }