1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-08 03:31:59 +02:00
goreleaser/cmd/completion.go
Carlos Alexandro Becker afda24a1e9
feat: add fish completion (#1860)
refs #1858 # #1859

Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
2020-10-16 11:01:36 +00:00

35 lines
784 B
Go

package cmd
import "github.com/spf13/cobra"
type completionCmd struct {
cmd *cobra.Command
}
func newCompletionCmd() *completionCmd {
var root = &completionCmd{}
var cmd = &cobra.Command{
Use: "completion",
Short: "Print shell autocompletion scripts for goreleaser",
SilenceUsage: true,
ValidArgs: []string{"bash", "zsh", "fish"},
Args: cobra.ExactValidArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var err error
switch args[0] {
case "bash":
err = cmd.Root().GenBashCompletion(cmd.OutOrStdout())
case "zsh":
err = cmd.Root().GenZshCompletion(cmd.OutOrStdout())
case "fish":
err = cmd.Root().GenFishCompletion(cmd.OutOrStdout(), true)
}
return err
},
}
root.cmd = cmd
return root
}