Skip to content

Commit

Permalink
Adds verification to number of args for completion cmd
Browse files Browse the repository at this point in the history
The completion cmd requires at least one extra argument but it
doesn't check cobra args before switch statement, causing panic.
This commit fixes #210.

(cherry picked from commit e5c62cc)
  • Loading branch information
davivcgarcia authored and vdemeester committed Aug 13, 2019
1 parent 4b04b4d commit f18e2d0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ func Command() *cobra.Command {
ValidArgs: []string{"bash", "zsh"},
Example: eg,
RunE: func(cmd *cobra.Command, args []string) error {
switch args[0] {
case "bash":
return cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
return runCompletionZsh(os.Stdout, cmd.Parent())
if len(args) == 1 {
switch args[0] {
case "bash":
return cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
return runCompletionZsh(os.Stdout, cmd.Parent())
}
}
return nil
},
Expand Down

0 comments on commit f18e2d0

Please sign in to comment.