@@ -164,30 +164,34 @@ func categorizeFlags(usageOutput string) string {
164
164
var prevBody string
165
165
166
166
for _ , cat := range flagCategories {
167
- if buf , ok := categories [cat .name ]; ok {
168
- // If the last line of the previous category is a single-line flag,
169
- // then it isn't indented, and an additional newline is necessary to
170
- // make the output readable.
171
- if prevBody != "" {
172
- prevBodyLines := strings .Split (strings .TrimSpace (prevBody ), "\n " )
173
- if len (prevBodyLines ) > 0 {
174
- lastLine := prevBodyLines [len (prevBodyLines )- 1 ]
175
- if strings .HasPrefix (strings .TrimSpace (lastLine ), "-" ) {
176
- _ , _ = out .WriteString ("\n " )
177
- }
167
+ buf , ok := categories [cat .name ]
168
+ if ! ok {
169
+ continue
170
+ }
171
+
172
+ // If the last line of the previous category is a single-line flag,
173
+ // then it isn't indented, and an additional newline is necessary to
174
+ // make the output readable.
175
+ if prevBody != "" {
176
+ prevBodyLines := strings .Split (strings .TrimSpace (prevBody ), "\n " )
177
+ if len (prevBodyLines ) > 0 {
178
+ lastLine := prevBodyLines [len (prevBodyLines )- 1 ]
179
+ if strings .HasPrefix (strings .TrimSpace (lastLine ), "-" ) {
180
+ _ , _ = out .WriteString ("\n " )
178
181
}
179
182
}
183
+ }
180
184
181
- if len (categories ) == 1 {
182
- // Don't bother qualifying list if there's only one category.
183
- _ , _ = fmt .Fprintf (& out , "%s\n " , usageHeader ("Flags:" ))
184
- } else {
185
- _ , _ = fmt .Fprintf (& out , "%s\n " , usageHeader (cat .name + " Flags:" ))
186
- }
187
- body := buf .String ()
188
- _ , _ = out .WriteString (body )
189
- prevBody = body
185
+ if len (categories ) == 1 {
186
+ // Don't bother qualifying list name if there's only one category.
187
+ _ , _ = fmt .Fprintf (& out , "%s\n " , usageHeader ("Flags:" ))
188
+ } else {
189
+ _ , _ = fmt .Fprintf (& out , "%s\n " , usageHeader (cat .name + " Flags:" ))
190
190
}
191
+
192
+ body := buf .String ()
193
+ _ , _ = out .WriteString (body )
194
+ prevBody = body
191
195
}
192
196
193
197
return out .String ()
0 commit comments