Skip to content

Commit 9052c01

Browse files
committed
fixup! Update golden files
1 parent ae42a13 commit 9052c01

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

cli/usage.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ type flagCategory struct {
5454
matchers []*regexp.Regexp
5555
}
5656

57-
// flagCategories are evaluated by categorizeFlags in order. The first matched
58-
// category is used for each flag declaration.
57+
// flagCategories are evaluated by categorizeFlags in order. Evaluation ends
58+
// once the first category is matched.
5959
var flagCategories = []flagCategory{
6060
{
6161
name: "Networking",
@@ -124,22 +124,27 @@ func categorizeFlags(usageOutput string) string {
124124

125125
for _, cat := range flagCategories {
126126
for _, matcher := range cat.matchers {
127-
if matcher.MatchString(currentFlag.String()) {
128-
if _, ok := categories[cat.name]; !ok {
129-
categories[cat.name] = &bytes.Buffer{}
130-
}
131-
if os.Getenv("DEBUG_FLAG_CATEGORIZATION") != "" {
132-
_, _ = os.Stderr.WriteString(
133-
fmt.Sprintf(
134-
"--- \n%s\nwas matched by `%s`\n---\n",
135-
currentFlag.String(), matcher.String(),
136-
),
137-
)
138-
}
139-
_, _ = categories[cat.name].WriteString(currentFlag.String())
140-
currentFlag.Reset()
141-
return
127+
if !matcher.MatchString(currentFlag.String()) {
128+
continue
129+
}
130+
131+
catBuf, ok := categories[cat.name]
132+
if !ok {
133+
catBuf = &bytes.Buffer{}
134+
categories[cat.name] = catBuf
142135
}
136+
137+
if os.Getenv("DEBUG_FLAG_CATEGORIZATION") != "" {
138+
_, _ = os.Stderr.WriteString(
139+
fmt.Sprintf(
140+
"--- \n%s\nwas matched by `%s`\n---\n",
141+
currentFlag.String(), matcher.String(),
142+
),
143+
)
144+
}
145+
146+
_, _ = currentFlag.WriteTo(catBuf)
147+
return
143148
}
144149
}
145150

0 commit comments

Comments
 (0)