Skip to content

Commit

Permalink
Merge pull request #9950 from kranurag7/kr/add-fish-completion
Browse files Browse the repository at this point in the history
🌱 Add completion for fish shell
  • Loading branch information
k8s-ci-robot committed Jan 19, 2024
2 parents 8ed14d7 + 9519d43 commit f335f13
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmd/clusterctl/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
Expand Down Expand Up @@ -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 {
Expand All @@ -100,6 +104,7 @@ var (
completionShells = map[string]func(out io.Writer, cmd *cobra.Command) error{
"bash": runCompletionBash,
"zsh": runCompletionZsh,
"fish": runCompletionFish,
}
)

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f335f13

Please sign in to comment.