diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b8ff944e8..454cf7074 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,16 +36,10 @@ Anyone can comment on issues and submit reviews for pull requests. In order to b - The project tries to follow the following grammar for the commands: ```bash -clusteradm [] +clusteradm [subcmd] [flags] ``` -- A number of verbs are already defined in [verbs](pkg/cmd/verbs/verbs.go), if you would like to add a new verb or noun, please contact the [OWNERS](OWNERS). - -- The noun represents the object on which the verb applies. - -- Each pair (verb/[noum]) has its own package. - -- Inside the package, the code is split in 3 files: The [cmd.go](pkg/cmd/version/cmd.go) which creates the cobra command, the [options.go](pkg/cmd/version/options.go) which defines the different option parameters for the command and the the [exec.go](pkg/cmd/version/exec.go) which contains the code to execute the command. +- Each cmd/subcmd are in a package, the code is split in 3 files: The [cmd.go](pkg/cmd/version/cmd.go) which creates the cobra command, the [options.go](pkg/cmd/version/options.go) which defines the different option parameters for the command and the the [exec.go](pkg/cmd/version/exec.go) which contains the code to execute the command. ## Resources diff --git a/cmd/clusteradm.go b/cmd/clusteradm.go index 480d6455f..a753b9e0e 100644 --- a/cmd/clusteradm.go +++ b/cmd/clusteradm.go @@ -1,6 +1,6 @@ // Copyright Contributors to the Open Cluster Management project -package main +package cmd import ( "os" @@ -13,7 +13,12 @@ import ( "k8s.io/kubectl/pkg/cmd/options" "k8s.io/kubectl/pkg/cmd/plugin" cmdutil "k8s.io/kubectl/pkg/cmd/util" - "open-cluster-management.io/clusteradm/pkg/cmd/verbs" + ktemplates "k8s.io/kubectl/pkg/util/templates" + "open-cluster-management.io/clusteradm/pkg/cmd/version" + + acceptclusters "open-cluster-management.io/clusteradm/pkg/cmd/accept" + inithub "open-cluster-management.io/clusteradm/pkg/cmd/init" + joinhub "open-cluster-management.io/clusteradm/pkg/cmd/join" ) func main() { @@ -22,7 +27,11 @@ func main() { matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(configFlags) f := cmdutil.NewFactory(matchVersionKubeConfigFlags) - root := newCmdVerbs("clusteradm", f, streams) + root := + &cobra.Command{ + Use: "clusteradm", + } + // root := newCmdVerbs("clusteradm", f, streams) flags := root.PersistentFlags() matchVersionKubeConfigFlags.AddFlags(flags) @@ -39,20 +48,24 @@ func main() { plugin.ValidPluginFilenamePrefixes = []string{os.Args[0]} root.AddCommand(plugin.NewCmdPlugin(f, streams)) + groups := ktemplates.CommandGroups{ + { + Message: "General commands:", + Commands: []*cobra.Command{ + version.NewCmd(f, streams), + }, + }, + { + Message: "Registration commands:", + Commands: []*cobra.Command{ + inithub.NewCmd(f, streams), + joinhub.NewCmd(f, streams), + acceptclusters.NewCmd(f, streams), + }, + }, + } + groups.Add(root) if err := root.Execute(); err != nil { os.Exit(1) } } - -// NewCmdNamespace provides a cobra command wrapping NamespaceOptions -func newCmdVerbs(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { - cmd := &cobra.Command{Use: parent} - cmd.AddCommand( - verbs.NewVerbVersion("version", f, streams), - verbs.NewVerbInit("init", f, streams), - verbs.NewVerbJoin("join", f, streams), - verbs.NewVerbAccept("accept", f, streams), - ) - - return cmd -} diff --git a/pkg/cmd/verbs/verbs.go b/pkg/cmd/verbs/verbs.go deleted file mode 100644 index b41479571..000000000 --- a/pkg/cmd/verbs/verbs.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright Contributors to the Open Cluster Management project -package verbs - -import ( - "github.com/spf13/cobra" - "open-cluster-management.io/clusteradm/pkg/cmd/version" - - "k8s.io/cli-runtime/pkg/genericclioptions" - - cmdutil "k8s.io/kubectl/pkg/cmd/util" - acceptclusters "open-cluster-management.io/clusteradm/pkg/cmd/accept" - inithub "open-cluster-management.io/clusteradm/pkg/cmd/init" - joinhub "open-cluster-management.io/clusteradm/pkg/cmd/join" -) - -func NewVerbVersion(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { - cmd := version.NewCmd(f, streams) - - return cmd -} - -func NewVerbInit(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { - return inithub.NewCmd(f, streams) -} - -func NewVerbJoin(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { - return joinhub.NewCmd(f, streams) -} - -func NewVerbAccept(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command { - return acceptclusters.NewCmd(f, streams) -}