Added some ctl boilerplate

This commit is contained in:
2026-03-27 18:34:53 +08:00
parent bf85462e34
commit 87aa1d4b0b
30 changed files with 1813 additions and 19 deletions

View File

@@ -0,0 +1,41 @@
package root
import (
"flag"
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"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/klog/v2"
)
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) {
klog.InitFlags(nil)
_ = flag.Set("logtostderr", "true")
},
}
flags.AddFlags(cmd.PersistentFlags())
cmd.AddCommand(
initcmd.NewCmdInit(flags),
checkconfigcmd.NewCmdCheckConfig(),
createcmd.NewCmdCreate(),
applycmd.NewCmdApply(flags),
agentcmd.NewCmdAgent(flags),
internalcmd.NewCmdInternal(),
)
return cmd
}