@@ -54,8 +54,8 @@ type flagCategory struct {
54
54
matchers []* regexp.Regexp
55
55
}
56
56
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 .
59
59
var flagCategories = []flagCategory {
60
60
{
61
61
name : "Networking" ,
@@ -124,22 +124,27 @@ func categorizeFlags(usageOutput string) string {
124
124
125
125
for _ , cat := range flagCategories {
126
126
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\n was 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
142
135
}
136
+
137
+ if os .Getenv ("DEBUG_FLAG_CATEGORIZATION" ) != "" {
138
+ _ , _ = os .Stderr .WriteString (
139
+ fmt .Sprintf (
140
+ "--- \n %s\n was matched by `%s`\n ---\n " ,
141
+ currentFlag .String (), matcher .String (),
142
+ ),
143
+ )
144
+ }
145
+
146
+ _ , _ = currentFlag .WriteTo (catBuf )
147
+ return
143
148
}
144
149
}
145
150
0 commit comments