esway/internal/cmd/root.go

27 lines
656 B
Go
Raw Normal View History

2024-12-19 15:03:36 +08:00
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...)
}