From 6eb8eb49479e58684f766c576c536793d2bfe0e4 Mon Sep 17 00:00:00 2001 From: zhzhuang-zju Date: Fri, 13 Sep 2024 15:59:31 +0800 Subject: [PATCH] update completionExample Signed-off-by: zhzhuang-zju --- pkg/karmadactl/completion/completion.go | 13 ++++++------- pkg/karmadactl/cordon/cordon.go | 5 +++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/karmadactl/completion/completion.go b/pkg/karmadactl/completion/completion.go index a934802c1e07..993874c670e5 100644 --- a/pkg/karmadactl/completion/completion.go +++ b/pkg/karmadactl/completion/completion.go @@ -54,16 +54,15 @@ var ( completionExample = templates.Examples(i18n.T(` # Installing bash completion on Linux ## If bash-completion is not installed on Linux, install the 'bash-completion' package + 1. apt-get install bash-completion + 2. source /usr/share/bash-completion/bash_completion ## via your distribution's package manager. ## Load the %[1]s completion code for bash into the current shell source <(%[1]s completion bash) - ## Write bash completion code to a file and source it from .bash_profile - %[1]s completion bash > ~/.kube/completion.bash.inc - printf " - # %[1]s shell completion - source '$HOME/.kube/completion.bash.inc' - " >> $HOME/.bash_profile - source $HOME/.bash_profile + ## Or, write bash completion code to a file and source it from .bash_profile + 1. %[1]s completion bash > ~/.kube/completion.bash.inc + 2. echo "source '$HOME/.kube/completion.bash.inc'" >> $HOME/.bash_profile + 3. source $HOME/.bash_profile # Load the %[1]s completion code for zsh[1] into the current shell source <(%[1]s completion zsh) diff --git a/pkg/karmadactl/cordon/cordon.go b/pkg/karmadactl/cordon/cordon.go index f8f9115a9853..90aa4958582d 100644 --- a/pkg/karmadactl/cordon/cordon.go +++ b/pkg/karmadactl/cordon/cordon.go @@ -62,6 +62,9 @@ const ( // NewCmdCordon defines the `cordon` command that mark cluster as unschedulable. func NewCmdCordon(f util.Factory, parentCommand string) *cobra.Command { opts := CommandCordonOption{} + + validArgs := []string{"cluster"} + cmd := &cobra.Command{ Use: "cordon CLUSTER", Short: "Mark cluster as unschedulable", @@ -69,6 +72,7 @@ func NewCmdCordon(f util.Factory, parentCommand string) *cobra.Command { Example: fmt.Sprintf(cordonExample, parentCommand), SilenceUsage: true, DisableFlagsInUseLine: true, + ValidArgsFunction: utilcomp.SpecifiedResourceTypeAndNameCompletionFunc(f, validArgs), RunE: func(_ *cobra.Command, args []string) error { if err := opts.Complete(args); err != nil { return err @@ -96,6 +100,7 @@ func NewCmdUncordon(f util.Factory, parentCommand string) *cobra.Command { opts := CommandCordonOption{} validArgs := []string{"cluster"} + cmd := &cobra.Command{ Use: "uncordon CLUSTER", Short: "Mark cluster as schedulable",