Skip to content

Commit

Permalink
Avoid infinitely walking up the command tree
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlandon committed Sep 30, 2023
1 parent d6df128 commit 5dad425
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion completions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 5dad425

Please sign in to comment.