Skip to content

Commit d64b825

Browse files
committed
Remove newCandidate, check for matches separately
1 parent e17f43d commit d64b825

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

context.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -685,18 +685,23 @@ func flipBoolValue(value reflect.Value) error {
685685
func (c *Context) parseFlag(flags []*Flag, match string) (err error) {
686686
candidates := []string{}
687687

688-
newCandidate := func(s string) bool {
689-
candidates = append(candidates, s)
690-
return s == match
691-
}
692-
693688
for _, flag := range flags {
694-
matched := newCandidate("--" + flag.Name)
689+
flagCandidates := []string{}
690+
flagCandidates = append(flagCandidates, "--"+flag.Name)
695691
if flag.Short != 0 {
696-
matched = matched || newCandidate("-"+string(flag.Short))
692+
flagCandidates = append(flagCandidates, "-"+string(flag.Short))
697693
}
698694
for _, alias := range flag.Aliases {
699-
matched = matched || newCandidate("--"+alias)
695+
flagCandidates = append(flagCandidates, "--"+alias)
696+
}
697+
candidates = append(candidates, flagCandidates...)
698+
699+
var matched bool
700+
for _, candidate := range flagCandidates {
701+
if candidate == match {
702+
matched = true
703+
break
704+
}
700705
}
701706

702707
neg := "--no-" + flag.Name

0 commit comments

Comments
 (0)