package root import ( "flag" "os" "github.com/spf13/cobra" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/klog/v2" agentcmd "undecided.project/monok8s/pkg/cmd/agent" applycmd "undecided.project/monok8s/pkg/cmd/apply" checkconfigcmd "undecided.project/monok8s/pkg/cmd/checkconfig" createcmd "undecided.project/monok8s/pkg/cmd/create" initcmd "undecided.project/monok8s/pkg/cmd/initcmd" internalcmd "undecided.project/monok8s/pkg/cmd/internal" versioncmd "undecided.project/monok8s/pkg/cmd/version" ) func init() { klog.InitFlags(nil) if os.Getenv("DEBUG") != "" { _ = flag.Set("v", "4") // debug level } else { _ = flag.Set("v", "0") } } func NewRootCmd() *cobra.Command { flags := genericclioptions.NewConfigFlags(true) cmd := &cobra.Command{ Use: "ctl", Short: "MonoK8s control tool", SilenceUsage: true, SilenceErrors: true, PersistentPreRun: func(*cobra.Command, []string) { _ = flag.Set("logtostderr", "true") }, } flags.AddFlags(cmd.PersistentFlags()) cmd.AddCommand( versioncmd.NewCmdVersion(), initcmd.NewCmdInit(flags), checkconfigcmd.NewCmdCheckConfig(), createcmd.NewCmdCreate(), applycmd.NewCmdApply(flags), agentcmd.NewCmdAgent(flags), internalcmd.NewCmdInternal(), ) return cmd }