|
|
|
@ -72,6 +72,16 @@ To load completions for every new session, execute once:
|
|
|
|
|
You will need to start a new shell for this setup to take effect.
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
const powershellCompDesc = `
|
|
|
|
|
Generate the autocompletion script for powershell.
|
|
|
|
|
|
|
|
|
|
To load completions in your current shell session:
|
|
|
|
|
PS C:\> helm completion powershell | Out-String | Invoke-Expression
|
|
|
|
|
|
|
|
|
|
To load completions for every new session, add the output of the above command
|
|
|
|
|
to your powershell profile.
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
noDescFlagName = "no-descriptions"
|
|
|
|
|
noDescFlagText = "disable completion descriptions"
|
|
|
|
@ -88,16 +98,16 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bash := &cobra.Command{
|
|
|
|
|
Use: "bash",
|
|
|
|
|
Short: "generate autocompletion script for bash",
|
|
|
|
|
Long: bashCompDesc,
|
|
|
|
|
Args: require.NoArgs,
|
|
|
|
|
DisableFlagsInUseLine: true,
|
|
|
|
|
ValidArgsFunction: noCompletions,
|
|
|
|
|
Use: "bash",
|
|
|
|
|
Short: "generate autocompletion script for bash",
|
|
|
|
|
Long: bashCompDesc,
|
|
|
|
|
Args: require.NoArgs,
|
|
|
|
|
ValidArgsFunction: noCompletions,
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
return runCompletionBash(out, cmd)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
bash.Flags().BoolVar(&disableCompDescriptions, noDescFlagName, false, noDescFlagText)
|
|
|
|
|
|
|
|
|
|
zsh := &cobra.Command{
|
|
|
|
|
Use: "zsh",
|
|
|
|
@ -123,13 +133,25 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
|
|
|
|
|
}
|
|
|
|
|
fish.Flags().BoolVar(&disableCompDescriptions, noDescFlagName, false, noDescFlagText)
|
|
|
|
|
|
|
|
|
|
cmd.AddCommand(bash, zsh, fish)
|
|
|
|
|
powershell := &cobra.Command{
|
|
|
|
|
Use: "powershell",
|
|
|
|
|
Short: "generate autocompletion script for powershell",
|
|
|
|
|
Long: powershellCompDesc,
|
|
|
|
|
Args: require.NoArgs,
|
|
|
|
|
ValidArgsFunction: noCompletions,
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
return runCompletionPowershell(out, cmd)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
powershell.Flags().BoolVar(&disableCompDescriptions, noDescFlagName, false, noDescFlagText)
|
|
|
|
|
|
|
|
|
|
cmd.AddCommand(bash, zsh, fish, powershell)
|
|
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
// both helm2 and helm3), we hook the new binary name to the completion function
|
|
|
|
@ -180,6 +202,13 @@ func runCompletionFish(out io.Writer, cmd *cobra.Command) error {
|
|
|
|
|
return cmd.Root().GenFishCompletion(out, !disableCompDescriptions)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runCompletionPowershell(out io.Writer, cmd *cobra.Command) error {
|
|
|
|
|
if disableCompDescriptions {
|
|
|
|
|
return cmd.Root().GenPowerShellCompletion(out)
|
|
|
|
|
}
|
|
|
|
|
return cmd.Root().GenPowerShellCompletionWithDesc(out)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Function to disable file completion
|
|
|
|
|
func noCompletions(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
|
|
return nil, cobra.ShellCompDirectiveNoFileComp
|
|
|
|
|