From cc222ef67a96d85540b5a4eccc260b57a2f7f3e4 Mon Sep 17 00:00:00 2001 From: Tadeu Andrade Date: Fri, 28 Aug 2020 11:00:35 -0300 Subject: [PATCH] (feature) Add fish shell completions --- cmd/root.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 8bf404ded..3e155b03a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -157,12 +157,17 @@ func printVersion() { fmt.Printf("k3s version %s (default)\n", version.K3sVersion) } +func generateFishCompletion(writer io.Writer) error { + return rootCmd.GenFishCompletion(writer, true) +} + // Completion var completionFunctions = map[string]func(io.Writer) error{ "bash": rootCmd.GenBashCompletion, "zsh": rootCmd.GenZshCompletion, "psh": rootCmd.GenPowerShellCompletion, "powershell": rootCmd.GenPowerShellCompletion, + "fish": generateFishCompletion, } // NewCmdCompletion creates a new completion command @@ -170,8 +175,8 @@ func NewCmdCompletion() *cobra.Command { // create new cobra command cmd := &cobra.Command{ Use: "completion SHELL", - Short: "Generate completion scripts for [bash, zsh, powershell | psh]", - Long: `Generate completion scripts for [bash, zsh, powershell | psh]`, + Short: "Generate completion scripts for [bash, zsh, fish, powershell | psh]", + Long: `Generate completion scripts for [bash, zsh, fish, powershell | psh]`, Args: cobra.ExactArgs(1), // TODO: NewCmdCompletion: add support for 0 args = auto detection Run: func(cmd *cobra.Command, args []string) { if f, ok := completionFunctions[args[0]]; ok {