Skip to content

Commit

Permalink
Add bash & zsh completion
Browse files Browse the repository at this point in the history
  • Loading branch information
davewongillies committed Mar 22, 2019
1 parent a316c95 commit da6ac24
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cmd/completion.go
@@ -0,0 +1,32 @@
package cmd

import (
"github.com/spf13/cobra"

"errors"
"os"
)

// bashCompletionCmd represents the completion command
var completionCmd = &cobra.Command{
Use: "completion [shell]",
Short: "Output shell completion code for the specified shell (bash or zsh)",
Long: "Output shell completion code for the specified shell (bash or zsh)",
ValidArgs: []string{"bash"},
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return cmd.Usage()
}
switch args[0] {
case "bash":
return rootCmd.GenBashCompletion(os.Stdout)
case "zsh":
return rootCmd.GenZshCompletion(os.Stdout)
}
return errors.New("Unsupported shell")
},
}

func init() {
rootCmd.AddCommand(completionCmd)
}

0 comments on commit da6ac24

Please sign in to comment.