@@ -182,10 +182,9 @@ func (c *documentationCommand) dumpSeveralFiles() error {
182
182
return err
183
183
}
184
184
185
- writer := bufio .NewWriter (f )
186
- _ , err = writer .WriteString (c .commandsIndex ())
185
+ err = c .writeIndex (f )
187
186
if err != nil {
188
- return err
187
+ return fmt . Errorf ( "writing index: %w" , err )
189
188
}
190
189
f .Close ()
191
190
}
@@ -271,9 +270,9 @@ func (c *documentationCommand) dumpEntries(w io.Writer) error {
271
270
}
272
271
273
272
if ! c .noIndex {
274
- _ , err := fmt . Fprintf ( w , "%s" , c . commandsIndex () )
273
+ err := c . writeIndex ( w )
275
274
if err != nil {
276
- return err
275
+ return fmt . Errorf ( "writing index: %w" , err )
277
276
}
278
277
}
279
278
@@ -310,19 +309,26 @@ func (c *documentationCommand) writeSections(w io.Writer, superCommands []string
310
309
return nil
311
310
}
312
311
313
- func (c * documentationCommand ) commandsIndex () string {
314
- index := "# Index\n "
312
+ // writeIndex writes the command index to the specified writer.
313
+ func (c * documentationCommand ) writeIndex (w io.Writer ) error {
314
+ _ , err := fmt .Fprintf (w , "# Index\n " )
315
+ if err != nil {
316
+ return err
317
+ }
315
318
316
319
listCommands := c .getSortedListCommands ()
317
320
for id , name := range listCommands {
318
321
if isDefaultCommand (name ) {
319
322
continue
320
323
}
321
- index += fmt .Sprintf ("%d. [%s](%s)\n " , id , name , c .linkForCommand (name ))
324
+ _ , err = fmt .Fprintf (w , "%d. [%s](%s)\n " , id , name , c .linkForCommand (name ))
325
+ if err != nil {
326
+ return err
327
+ }
322
328
// TODO: handle subcommands ??
323
329
}
324
- index += "---\n \n "
325
- return index
330
+ _ , err = fmt . Fprintf ( w , "---\n \n " )
331
+ return err
326
332
}
327
333
328
334
// Return the URL/location for the given command
0 commit comments