Co-authored-by: Julien Robert <julien@rbrt.fr>
This commit is contained in:
co-authored by
Julien Robert
parent
b0d20bce2b
commit
daaff088e2
@@ -11,12 +11,19 @@ import (
|
||||
|
||||
// findSubCommand finds a sub-command of the provided command whose Use
|
||||
// string is or begins with the provided subCmdName.
|
||||
// It verifies the command's aliases as well.
|
||||
func findSubCommand(cmd *cobra.Command, subCmdName string) *cobra.Command {
|
||||
for _, subCmd := range cmd.Commands() {
|
||||
use := subCmd.Use
|
||||
if use == subCmdName || strings.HasPrefix(use, subCmdName+" ") {
|
||||
return subCmd
|
||||
}
|
||||
|
||||
for _, alias := range subCmd.Aliases {
|
||||
if alias == subCmdName || strings.HasPrefix(alias, subCmdName+" ") {
|
||||
return subCmd
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user