gogs-cli/cmd/gogs/completion.go

30 lines
549 B
Go
Raw Normal View History

2019-08-14 12:06:45 +00:00
package main
import (
"errors"
"os"
"github.com/spf13/cobra"
)
var completionCmd = &cobra.Command{
Use: "completion bash|zsh",
Short: "Generate shell completion",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
shell := args[0]
switch shell {
case "bash":
return cmd.Parent().GenBashCompletion(os.Stdout)
case "zsh":
return cmd.Parent().GenZshCompletion(os.Stdout)
default:
return errors.New("valid shell are bash or zsh")
}
},
}
func init() {
RootCmd.AddCommand(completionCmd)
}