Avoid infinitely walking up the command tree

This commit is contained in:
maxlandon 2023-09-30 20:48:28 +02:00
parent d6df128a74
commit 5dad42575c
No known key found for this signature in database
GPG key ID: 2DE5C14975A86900

View file

@ -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)
}