PKGBUILD/cmd/completion/completion.go

43 lines
940 B
Go

package completion
import (
"os"
"github.com/spf13/cobra"
)
// InitCmd initialize all completion subcommands
func InitCmd(cmd *cobra.Command) error {
completionCmd := &cobra.Command{
Use: "completion",
Short: "Generates a shell completion file",
}
bashCompletionCmd := &cobra.Command{
Use: "bash",
Short: "Generates a bash completion file",
Args: cobra.NoArgs,
Example: "flucky completion bash",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.GenBashCompletion(os.Stdout)
},
}
zshCompletionCmd := &cobra.Command{
Use: "zsh",
Short: "Generate a zsh completion file",
Args: cobra.NoArgs,
Example: "flucky completion zsh",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.GenZshCompletion(os.Stdout)
},
}
completionCmd.AddCommand(bashCompletionCmd)
completionCmd.AddCommand(zshCompletionCmd)
cmd.AddCommand(completionCmd)
return nil
}