mirror of
https://github.com/spf13/cobra
synced 2025-05-05 21:07:24 +00:00
Merge b83ace34b5
into d236d29810
This commit is contained in:
commit
7d9b8967b7
1 changed files with 15 additions and 1 deletions
16
command.go
16
command.go
|
@ -103,6 +103,8 @@ type Command struct {
|
||||||
PersistentPostRunE func(cmd *Command, args []string) error
|
PersistentPostRunE func(cmd *Command, args []string) error
|
||||||
// DisableAutoGenTag remove
|
// DisableAutoGenTag remove
|
||||||
DisableAutoGenTag bool
|
DisableAutoGenTag bool
|
||||||
|
// Contains the 'calledName' rather than the alias that matched
|
||||||
|
calledName string
|
||||||
// Commands is the list of commands supported by this program.
|
// Commands is the list of commands supported by this program.
|
||||||
commands []*Command
|
commands []*Command
|
||||||
// Parent Command for this command
|
// Parent Command for this command
|
||||||
|
@ -464,7 +466,11 @@ func (c *Command) Find(args []string) (*Command, []string, error) {
|
||||||
nextSubCmd := argsWOflags[0]
|
nextSubCmd := argsWOflags[0]
|
||||||
matches := make([]*Command, 0)
|
matches := make([]*Command, 0)
|
||||||
for _, cmd := range c.commands {
|
for _, cmd := range c.commands {
|
||||||
if cmd.Name() == nextSubCmd || cmd.HasAlias(nextSubCmd) { // exact name or alias match
|
if cmd.Name() == nextSubCmd { // exact name
|
||||||
|
return innerfind(cmd, argsMinusFirstX(innerArgs, nextSubCmd))
|
||||||
|
}
|
||||||
|
if cmd.HasAlias(nextSubCmd) { // alias match
|
||||||
|
cmd.calledName = nextSubCmd
|
||||||
return innerfind(cmd, argsMinusFirstX(innerArgs, nextSubCmd))
|
return innerfind(cmd, argsMinusFirstX(innerArgs, nextSubCmd))
|
||||||
}
|
}
|
||||||
if EnablePrefixMatching {
|
if EnablePrefixMatching {
|
||||||
|
@ -947,6 +953,14 @@ func (c *Command) Name() string {
|
||||||
return c.name
|
return c.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CalledName returns how this command was called as (rather than its name)
|
||||||
|
func (c *Command) CalledName() string {
|
||||||
|
if "" == c.calledName {
|
||||||
|
return c.Name()
|
||||||
|
}
|
||||||
|
return c.calledName
|
||||||
|
}
|
||||||
|
|
||||||
// HasAlias determines if a given string is an alias of the command.
|
// HasAlias determines if a given string is an alias of the command.
|
||||||
func (c *Command) HasAlias(s string) bool {
|
func (c *Command) HasAlias(s string) bool {
|
||||||
for _, a := range c.Aliases {
|
for _, a := range c.Aliases {
|
||||||
|
|
Loading…
Add table
Reference in a new issue