Skip to content

Commit

Permalink
Remove the notion of verb, use groupCmds
Browse files Browse the repository at this point in the history
Signed-off-by: Dominique Vernier <[email protected]>
  • Loading branch information
itdove committed Jun 6, 2021
1 parent f99a6d5 commit dbe6982
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 56 deletions.
10 changes: 2 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <verb> [<noun>]
clusteradm <cmd> [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
Expand Down
45 changes: 29 additions & 16 deletions cmd/clusteradm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Contributors to the Open Cluster Management project

package main
package cmd

import (
"os"
Expand All @@ -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() {
Expand All @@ -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)
Expand All @@ -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
}
32 changes: 0 additions & 32 deletions pkg/cmd/verbs/verbs.go

This file was deleted.

0 comments on commit dbe6982

Please sign in to comment.