Skip to content

Commit dbe6982

Browse files
committed
Remove the notion of verb, use groupCmds
Signed-off-by: Dominique Vernier <[email protected]>
1 parent f99a6d5 commit dbe6982

File tree

3 files changed

+31
-56
lines changed

3 files changed

+31
-56
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,10 @@ Anyone can comment on issues and submit reviews for pull requests. In order to b
3636
- The project tries to follow the following grammar for the commands:
3737

3838
```bash
39-
clusteradm <verb> [<noun>]
39+
clusteradm <cmd> [subcmd] [flags]
4040
```
4141

42-
- 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).
43-
44-
- The noun represents the object on which the verb applies.
45-
46-
- Each pair (verb/[noum]) has its own package.
47-
48-
- 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.
42+
- 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.
4943

5044

5145
## Resources

cmd/clusteradm.go

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright Contributors to the Open Cluster Management project
22

3-
package main
3+
package cmd
44

55
import (
66
"os"
@@ -13,7 +13,12 @@ import (
1313
"k8s.io/kubectl/pkg/cmd/options"
1414
"k8s.io/kubectl/pkg/cmd/plugin"
1515
cmdutil "k8s.io/kubectl/pkg/cmd/util"
16-
"open-cluster-management.io/clusteradm/pkg/cmd/verbs"
16+
ktemplates "k8s.io/kubectl/pkg/util/templates"
17+
"open-cluster-management.io/clusteradm/pkg/cmd/version"
18+
19+
acceptclusters "open-cluster-management.io/clusteradm/pkg/cmd/accept"
20+
inithub "open-cluster-management.io/clusteradm/pkg/cmd/init"
21+
joinhub "open-cluster-management.io/clusteradm/pkg/cmd/join"
1722
)
1823

1924
func main() {
@@ -22,7 +27,11 @@ func main() {
2227
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(configFlags)
2328
f := cmdutil.NewFactory(matchVersionKubeConfigFlags)
2429

25-
root := newCmdVerbs("clusteradm", f, streams)
30+
root :=
31+
&cobra.Command{
32+
Use: "clusteradm",
33+
}
34+
// root := newCmdVerbs("clusteradm", f, streams)
2635

2736
flags := root.PersistentFlags()
2837
matchVersionKubeConfigFlags.AddFlags(flags)
@@ -39,20 +48,24 @@ func main() {
3948
plugin.ValidPluginFilenamePrefixes = []string{os.Args[0]}
4049
root.AddCommand(plugin.NewCmdPlugin(f, streams))
4150

51+
groups := ktemplates.CommandGroups{
52+
{
53+
Message: "General commands:",
54+
Commands: []*cobra.Command{
55+
version.NewCmd(f, streams),
56+
},
57+
},
58+
{
59+
Message: "Registration commands:",
60+
Commands: []*cobra.Command{
61+
inithub.NewCmd(f, streams),
62+
joinhub.NewCmd(f, streams),
63+
acceptclusters.NewCmd(f, streams),
64+
},
65+
},
66+
}
67+
groups.Add(root)
4268
if err := root.Execute(); err != nil {
4369
os.Exit(1)
4470
}
4571
}
46-
47-
// NewCmdNamespace provides a cobra command wrapping NamespaceOptions
48-
func newCmdVerbs(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
49-
cmd := &cobra.Command{Use: parent}
50-
cmd.AddCommand(
51-
verbs.NewVerbVersion("version", f, streams),
52-
verbs.NewVerbInit("init", f, streams),
53-
verbs.NewVerbJoin("join", f, streams),
54-
verbs.NewVerbAccept("accept", f, streams),
55-
)
56-
57-
return cmd
58-
}

pkg/cmd/verbs/verbs.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)