Skip to content

Commit f18e2d0

Browse files
davivcgarciavdemeester
authored andcommitted
Adds verification to number of args for completion cmd
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)
1 parent 4b04b4d commit f18e2d0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pkg/cmd/completion/completion.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ func Command() *cobra.Command {
4747
ValidArgs: []string{"bash", "zsh"},
4848
Example: eg,
4949
RunE: func(cmd *cobra.Command, args []string) error {
50-
switch args[0] {
51-
case "bash":
52-
return cmd.Root().GenBashCompletion(os.Stdout)
53-
case "zsh":
54-
return runCompletionZsh(os.Stdout, cmd.Parent())
50+
if len(args) == 1 {
51+
switch args[0] {
52+
case "bash":
53+
return cmd.Root().GenBashCompletion(os.Stdout)
54+
case "zsh":
55+
return runCompletionZsh(os.Stdout, cmd.Parent())
56+
}
5557
}
5658
return nil
5759
},

0 commit comments

Comments
 (0)