feat(comp): Move to Cobra's bash completion V2

Cobra's bash completion V2 has the following benefits:
- aligned with the completion logic for the other shells
- provides completion descriptions as for the other shells
- uses a 300-line shell script (versus 4K lines for V1)

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
pull/9421/head
Marc Khouzam 3 years ago committed by Marc Khouzam
parent c6dfb490ab
commit efe2638f87

@ -98,16 +98,16 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
} }
bash := &cobra.Command{ bash := &cobra.Command{
Use: "bash", Use: "bash",
Short: "generate autocompletion script for bash", Short: "generate autocompletion script for bash",
Long: bashCompDesc, Long: bashCompDesc,
Args: require.NoArgs, Args: require.NoArgs,
DisableFlagsInUseLine: true, ValidArgsFunction: noCompletions,
ValidArgsFunction: noCompletions,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runCompletionBash(out, cmd) return runCompletionBash(out, cmd)
}, },
} }
bash.Flags().BoolVar(&disableCompDescriptions, noDescFlagName, false, noDescFlagText)
zsh := &cobra.Command{ zsh := &cobra.Command{
Use: "zsh", Use: "zsh",
@ -151,7 +151,7 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
} }
func runCompletionBash(out io.Writer, cmd *cobra.Command) error { func runCompletionBash(out io.Writer, cmd *cobra.Command) error {
err := cmd.Root().GenBashCompletion(out) err := cmd.Root().GenBashCompletionV2(out, !disableCompDescriptions)
// In case the user renamed the helm binary (e.g., to be able to run // In case the user renamed the helm binary (e.g., to be able to run
// both helm2 and helm3), we hook the new binary name to the completion function // both helm2 and helm3), we hook the new binary name to the completion function

Loading…
Cancel
Save