From d351e3dc728b0651a85fcd333a875b94e367fc86 Mon Sep 17 00:00:00 2001 From: zhzhuang-zju Date: Wed, 4 Sep 2024 16:47:38 +0800 Subject: [PATCH] add commandGroup annotation to ctl command Signed-off-by: zhzhuang-zju --- hack/tools/genkarmadactldocs/gen_karmadactl_docs.go | 2 +- pkg/karmadactl/annotate/annotate.go | 3 +++ pkg/karmadactl/apiresources/apiresources.go | 3 +++ pkg/karmadactl/apiresources/apiversions.go | 3 +++ pkg/karmadactl/attach/attach.go | 3 +++ pkg/karmadactl/create/create.go | 3 +++ pkg/karmadactl/delete/delete.go | 3 +++ pkg/karmadactl/edit/edit.go | 3 +++ pkg/karmadactl/explain/explain.go | 3 +++ pkg/karmadactl/label/label.go | 3 +++ pkg/karmadactl/patch/patch.go | 3 +++ pkg/karmadactl/top/top.go | 3 +++ pkg/karmadactl/util/command_group.go | 6 ++++++ 13 files changed, 40 insertions(+), 1 deletion(-) diff --git a/hack/tools/genkarmadactldocs/gen_karmadactl_docs.go b/hack/tools/genkarmadactldocs/gen_karmadactl_docs.go index 5a4dbce77..628acf6da 100644 --- a/hack/tools/genkarmadactldocs/gen_karmadactl_docs.go +++ b/hack/tools/genkarmadactldocs/gen_karmadactl_docs.go @@ -71,7 +71,7 @@ func GenMarkdownTreeForIndex(cmd *cobra.Command, dir string) error { return err } - for _, tp := range []string{util.GroupBasic, util.GroupClusterRegistration, util.GroupClusterManagement, util.GroupClusterTroubleshootingAndDebugging, util.GroupAdvancedCommands} { + for _, tp := range []string{util.GroupBasic, util.GroupClusterRegistration, util.GroupClusterManagement, util.GroupClusterTroubleshootingAndDebugging, util.GroupAdvancedCommands, util.GroupSettingsCommands, util.GroupOtherCommands} { // write header of type _, err = io.WriteString(f, "## "+tp+"\n\n") if err != nil { diff --git a/pkg/karmadactl/annotate/annotate.go b/pkg/karmadactl/annotate/annotate.go index 934d17769..dcd752d96 100644 --- a/pkg/karmadactl/annotate/annotate.go +++ b/pkg/karmadactl/annotate/annotate.go @@ -51,5 +51,8 @@ var ( func NewCmdAnnotate(f util.Factory, parentCommand string, ioStreams genericiooptions.IOStreams) *cobra.Command { cmd := kubectlannotate.NewCmdAnnotate(parentCommand, f, ioStreams) cmd.Example = fmt.Sprintf(annotateExample, parentCommand) + cmd.Annotations = map[string]string{ + util.TagCommandGroup: util.GroupSettingsCommands, + } return cmd } diff --git a/pkg/karmadactl/apiresources/apiresources.go b/pkg/karmadactl/apiresources/apiresources.go index a5be361f7..264504851 100644 --- a/pkg/karmadactl/apiresources/apiresources.go +++ b/pkg/karmadactl/apiresources/apiresources.go @@ -65,6 +65,9 @@ func NewCmdAPIResources(f util.Factory, parentCommand string, ioStreams generici cmdutil.CheckErr(o.Validate()) cmdutil.CheckErr(o.RunAPIResources()) }, + Annotations: map[string]string{ + util.TagCommandGroup: util.GroupOtherCommands, + }, } o.OperationScope = options.KarmadaControlPlane diff --git a/pkg/karmadactl/apiresources/apiversions.go b/pkg/karmadactl/apiresources/apiversions.go index 1726a4277..3aede352f 100644 --- a/pkg/karmadactl/apiresources/apiversions.go +++ b/pkg/karmadactl/apiresources/apiversions.go @@ -53,6 +53,9 @@ func NewCmdAPIVersions(f util.Factory, parentCommand string, ioStreams genericio cmdutil.CheckErr(o.Validate()) cmdutil.CheckErr(o.RunAPIVersions()) }, + Annotations: map[string]string{ + util.TagCommandGroup: util.GroupOtherCommands, + }, } o.OperationScope = options.KarmadaControlPlane diff --git a/pkg/karmadactl/attach/attach.go b/pkg/karmadactl/attach/attach.go index 9676bfab1..d92227254 100644 --- a/pkg/karmadactl/attach/attach.go +++ b/pkg/karmadactl/attach/attach.go @@ -70,6 +70,9 @@ func NewCmdAttach(f util.Factory, parentCommand string, streams genericiooptions cmdutil.CheckErr(o.Validate()) cmdutil.CheckErr(o.Run()) }, + Annotations: map[string]string{ + util.TagCommandGroup: util.GroupClusterTroubleshootingAndDebugging, + }, } cmdutil.AddPodRunningTimeoutFlag(cmd, defaultPodAttachTimeout) diff --git a/pkg/karmadactl/create/create.go b/pkg/karmadactl/create/create.go index 7f5a1213f..10b22a7cb 100644 --- a/pkg/karmadactl/create/create.go +++ b/pkg/karmadactl/create/create.go @@ -49,5 +49,8 @@ func NewCmdCreate(f util.Factory, parentCommnd string, ioStreams genericiooption cmd := kubectlcreate.NewCmdCreate(f, ioStreams) cmd.Long = fmt.Sprintf(createLong, parentCommnd) cmd.Example = fmt.Sprintf(createExample, parentCommnd) + cmd.Annotations = map[string]string{ + util.TagCommandGroup: util.GroupBasic, + } return cmd } diff --git a/pkg/karmadactl/delete/delete.go b/pkg/karmadactl/delete/delete.go index 1a48c1b49..aa007daa0 100644 --- a/pkg/karmadactl/delete/delete.go +++ b/pkg/karmadactl/delete/delete.go @@ -92,5 +92,8 @@ func NewCmdDelete(f util.Factory, parentCommnd string, ioStreams genericiooption cmd := kubectldelete.NewCmdDelete(f, ioStreams) cmd.Long = fmt.Sprintf(deleteLong, parentCommnd) cmd.Example = fmt.Sprintf(deleteExample, parentCommnd) + cmd.Annotations = map[string]string{ + util.TagCommandGroup: util.GroupBasic, + } return cmd } diff --git a/pkg/karmadactl/edit/edit.go b/pkg/karmadactl/edit/edit.go index e90828f1f..6487d5cfe 100644 --- a/pkg/karmadactl/edit/edit.go +++ b/pkg/karmadactl/edit/edit.go @@ -50,5 +50,8 @@ var ( func NewCmdEdit(f util.Factory, parentCommand string, ioStreams genericiooptions.IOStreams) *cobra.Command { cmd := kubectledit.NewCmdEdit(f, ioStreams) cmd.Example = fmt.Sprintf(editExample, parentCommand) + cmd.Annotations = map[string]string{ + util.TagCommandGroup: util.GroupBasic, + } return cmd } diff --git a/pkg/karmadactl/explain/explain.go b/pkg/karmadactl/explain/explain.go index 7b5bbfbac..52378a78a 100644 --- a/pkg/karmadactl/explain/explain.go +++ b/pkg/karmadactl/explain/explain.go @@ -74,6 +74,9 @@ func NewCmdExplain(f util.Factory, parentCommand string, streams genericiooption cmdutil.CheckErr(o.Validate()) cmdutil.CheckErr(o.Run()) }, + Annotations: map[string]string{ + util.TagCommandGroup: util.GroupBasic, + }, } flags := cmd.Flags() diff --git a/pkg/karmadactl/label/label.go b/pkg/karmadactl/label/label.go index aa308bd25..fafb7b928 100644 --- a/pkg/karmadactl/label/label.go +++ b/pkg/karmadactl/label/label.go @@ -50,5 +50,8 @@ var ( func NewCmdLabel(f util.Factory, parentCommand string, ioStreams genericiooptions.IOStreams) *cobra.Command { cmd := kubectllabel.NewCmdLabel(f, ioStreams) cmd.Example = fmt.Sprintf(labelExample, parentCommand) + cmd.Annotations = map[string]string{ + util.TagCommandGroup: util.GroupSettingsCommands, + } return cmd } diff --git a/pkg/karmadactl/patch/patch.go b/pkg/karmadactl/patch/patch.go index 859f878e8..09d8e3be0 100644 --- a/pkg/karmadactl/patch/patch.go +++ b/pkg/karmadactl/patch/patch.go @@ -46,5 +46,8 @@ var ( func NewCmdPatch(f util.Factory, parentCommand string, ioStreams genericiooptions.IOStreams) *cobra.Command { cmd := kubectlpatch.NewCmdPatch(f, ioStreams) cmd.Example = fmt.Sprintf(patchExample, parentCommand) + cmd.Annotations = map[string]string{ + util.TagCommandGroup: util.GroupAdvancedCommands, + } return cmd } diff --git a/pkg/karmadactl/top/top.go b/pkg/karmadactl/top/top.go index 235b81727..1241102b1 100644 --- a/pkg/karmadactl/top/top.go +++ b/pkg/karmadactl/top/top.go @@ -58,6 +58,9 @@ func NewCmdTop(f util.Factory, parentCommand string, streams genericiooptions.IO Short: "Display resource (CPU/memory) usage of member clusters", Long: topLong, Run: cmdutil.DefaultSubCommandRun(streams.ErrOut), + Annotations: map[string]string{ + util.TagCommandGroup: util.GroupAdvancedCommands, + }, } // create subcommands diff --git a/pkg/karmadactl/util/command_group.go b/pkg/karmadactl/util/command_group.go index 4899d4f4f..c9eb67ed2 100644 --- a/pkg/karmadactl/util/command_group.go +++ b/pkg/karmadactl/util/command_group.go @@ -36,4 +36,10 @@ const ( // GroupAdvancedCommands means the command belongs to Group "Advanced Commands" GroupAdvancedCommands = "Advanced Commands" + + // GroupSettingsCommands means the command belongs to Group "Settings Commands" + GroupSettingsCommands = "Settings Commands" + + // GroupOtherCommands means the command belongs to Group "Other Commands" + GroupOtherCommands = "Other Commands" )