Merge "[#10] Perform early validation of completion cmd"
This commit is contained in:
commit
ec6d1e408b
@ -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])
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user