nf/nft/nfctl/internal/cmd/cmd.root.go
2024-12-26 19:20:17 -08:00

34 lines
814 B
Go

package cmd
import (
"github.com/loveuer/nf/nft/log"
"github.com/loveuer/nf/nft/nfctl/internal/opt"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "nfctl",
Short: "nfctl is a tool for quick start a nf projects",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if opt.Cfg.Debug {
log.SetLogLevel(log.LogLevelDebug)
}
if !opt.Cfg.DisableUpdate {
doUpdate(cmd.Context())
}
return nil
},
DisableSuggestions: true,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {},
}
func initRoot(cmds ...*cobra.Command) {
rootCmd.PersistentFlags().BoolVar(&opt.Cfg.Debug, "debug", false, "debug mode")
rootCmd.PersistentFlags().BoolVar(&opt.Cfg.DisableUpdate, "disable-update", false, "disable self update")
rootCmd.AddCommand(cmds...)
}