Merge "[#10] Perform early validation of completion cmd"

This commit is contained in:
Zuul 2020-02-12 07:48:06 +00:00 committed by Gerrit Code Review
commit ec6d1e408b
2 changed files with 1 additions and 18 deletions

View File

@ -36,6 +36,7 @@ func NewCompletionCommand() *cobra.Command {
Use: "completion SHELL",
Short: "Generate autocompletions script for the specified shell (bash or zsh)",
Long: completionDesc,
Args: cobra.ExactArgs(1),
RunE: runCompletion,
ValidArgs: shells,
}
@ -44,12 +45,6 @@ func NewCompletionCommand() *cobra.Command {
}
func runCompletion(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("shell not specified")
}
if len(args) > 1 {
return fmt.Errorf("too many arguments, expected only the shell type")
}
run, found := completionShells[args[0]]
if !found {
return fmt.Errorf("unsupported shell type %q", args[0])

View File

@ -22,18 +22,6 @@ func TestCompletion(t *testing.T) {
CmdLine: "zsh",
Cmd: cmd,
},
{
Name: "completion-no-args",
CmdLine: "",
Cmd: cmd,
Error: errors.New("shell not specified"),
},
{
Name: "completion-too-many-args",
CmdLine: "bash zsh",
Cmd: cmd,
Error: errors.New("too many arguments, expected only the shell type"),
},
{
Name: "completion-unknown-shell",
CmdLine: "fish",