Skip to content

Commit

Permalink
Merge pull request #345 from mtatheonly/fish-completion
Browse files Browse the repository at this point in the history
[Feature] Add fish shell completions (thanks @mtatheonly)
  • Loading branch information
iwilltry42 authored Sep 2, 2020
2 parents 9bf264a + cc222ef commit 2d2713a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,26 @@ 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
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 {
Expand Down

0 comments on commit 2d2713a

Please sign in to comment.