diff --git a/cmd/clusterctl/cmd/completion.go b/cmd/clusterctl/cmd/completion.go index 11812b0ad96d..935194a1dfa6 100644 --- a/cmd/clusterctl/cmd/completion.go +++ b/cmd/clusterctl/cmd/completion.go @@ -49,7 +49,7 @@ const completionBoilerPlate = `# Copyright 2021 The Kubernetes Authors. var ( completionLong = LongDesc(` - Output shell completion code for the specified shell (bash or zsh). + Output shell completion code for the specified shell (bash, zsh or fish). The shell code must be evaluated to provide interactive completion of clusterctl commands. This can be done by sourcing it from the .bash_profile.`) @@ -77,12 +77,16 @@ var ( # To load completions for each session, execute once: clusterctl completion zsh > "${fpath[1]}/_clusterctl" + Fish: + # To load completions in your current shell, execute the following command: + clusterctl completion fish | source + # You will need to start a new shell for this setup to take effect.`) completionCmd = &cobra.Command{ - Use: "completion [bash|zsh]", + Use: "completion [bash|zsh|fish]", GroupID: groupOther, - Short: "Output shell completion code for the specified shell (bash or zsh)", + Short: "Output shell completion code for the specified shell (bash, zsh or fish)", Long: LongDesc(completionLong), Example: completionExample, Args: func(cmd *cobra.Command, args []string) error { @@ -100,6 +104,7 @@ var ( completionShells = map[string]func(out io.Writer, cmd *cobra.Command) error{ "bash": runCompletionBash, "zsh": runCompletionZsh, + "fish": runCompletionFish, } ) @@ -131,6 +136,12 @@ func runCompletionBash(out io.Writer, cmd *cobra.Command) error { return cmd.Root().GenBashCompletion(out) } +func runCompletionFish(out io.Writer, cmd *cobra.Command) error { + fmt.Fprintf(out, "%s\n", completionBoilerPlate) + + return cmd.Root().GenFishCompletion(out, true) +} + func runCompletionZsh(out io.Writer, cmd *cobra.Command) error { var b bytes.Buffer