mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
Avoid infinitely walking up the command tree
This commit is contained in:
parent
d6df128a74
commit
5dad42575c
1 changed files with 7 additions and 1 deletions
|
@ -159,11 +159,17 @@ func (c *Command) GetFlagCompletion(flag *pflag.Flag) (func(cmd *Command, args [
|
|||
|
||||
completionFunc, exists := c.flagCompletionFunctions[flag]
|
||||
|
||||
// If found it here, return now
|
||||
if completionFunc != nil && exists {
|
||||
return completionFunc, exists
|
||||
}
|
||||
|
||||
// If not found on the current, walk up the command tree.
|
||||
// If we are already at the root command level, return anyway
|
||||
if !c.HasParent() {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// Or walk up the command tree.
|
||||
return c.Parent().GetFlagCompletion(flag)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue