@@ -20,6 +20,10 @@ func executeRunCmd(args []string) {
20
20
os .Exit (0 )
21
21
}
22
22
23
+ func isHelpOrVersionFlag (flag string ) bool {
24
+ return flag == "-h" || flag != "--help" || flag == "-v" || flag == "--version"
25
+ }
26
+
23
27
func bootstrapCmdPlugin (cmd * cobra.Command , pluginHandler plugin.PluginHandler ) {
24
28
if pluginHandler == nil {
25
29
return
@@ -30,7 +34,7 @@ func bootstrapCmdPlugin(cmd *cobra.Command, pluginHandler plugin.PluginHandler)
30
34
// only look for suitable extension executables if
31
35
// the specified command does not already exist
32
36
// flags cannot be placed before plugin name
33
- if strings .HasPrefix (cmdPathPieces [0 ], "-" ) {
37
+ if strings .HasPrefix (cmdPathPieces [0 ], "-" ) && ! isHelpOrVersionFlag ( cmdPathPieces [ 0 ]) {
34
38
executeRunCmd (cmdPathPieces )
35
39
} else if foundCmd , _ , err := cmd .Find (cmdPathPieces ); err != nil {
36
40
// Also check the commands that will be added by Cobra.
@@ -44,18 +48,18 @@ func bootstrapCmdPlugin(cmd *cobra.Command, pluginHandler plugin.PluginHandler)
44
48
}
45
49
}
46
50
47
- builtinSubcmdExist := false
48
- for _ , subcmd := range foundCmd .Commands () {
49
- if subcmd .Name () == cmdName {
50
- builtinSubcmdExist = true
51
+ builtinSubCmdExist := false
52
+ for _ , cmd := range foundCmd .Commands () {
53
+ if cmd .Name () == cmdName {
54
+ builtinSubCmdExist = true
51
55
break
52
56
}
53
57
}
54
58
switch cmdName {
55
59
// Don't search for a plugin
56
60
case "help" , cobra .ShellCompRequestCmd , cobra .ShellCompNoDescRequestCmd :
57
61
default :
58
- if ! builtinSubcmdExist {
62
+ if ! builtinSubCmdExist {
59
63
if err := plugin .HandlePluginCommand (pluginHandler , cmdPathPieces , false ); err != nil {
60
64
fmt .Fprintf (os .Stderr , "Error: %v\n " , err )
61
65
os .Exit (1 )
0 commit comments