(doc: HelpDoc, colors: ColorFunctions)
| 435 | * @internal |
| 436 | */ |
| 437 | const formatHelpDocImpl = (doc: HelpDoc, colors: ColorFunctions): string => { |
| 438 | const sections: Array<string> = [] |
| 439 | |
| 440 | // Description section |
| 441 | if (doc.description) { |
| 442 | sections.push(colors.bold("DESCRIPTION")) |
| 443 | sections.push(` ${doc.description}`) |
| 444 | sections.push("") |
| 445 | } |
| 446 | |
| 447 | // Usage section |
| 448 | sections.push(colors.bold("USAGE")) |
| 449 | sections.push(` ${colors.cyan(doc.usage)}`) |
| 450 | sections.push("") |
| 451 | |
| 452 | // Arguments section |
| 453 | if (doc.args && doc.args.length > 0) { |
| 454 | sections.push(colors.bold("ARGUMENTS")) |
| 455 | |
| 456 | const argRows: Array<Row> = doc.args.map((arg) => { |
| 457 | let name = arg.name |
| 458 | if (arg.variadic) { |
| 459 | name += "..." |
| 460 | } |
| 461 | |
| 462 | const coloredName = colors.green(name) |
| 463 | const coloredType = colors.dim(arg.type) |
| 464 | const nameType = `${coloredName} ${coloredType}` |
| 465 | |
| 466 | const optionalSuffix = arg.required ? "" : colors.dim(" (optional)") |
| 467 | const description = Option.getOrElse(arg.description, () => "") + optionalSuffix |
| 468 | |
| 469 | return { |
| 470 | left: nameType, |
| 471 | right: description |
| 472 | } |
| 473 | }) |
| 474 | |
| 475 | sections.push(renderTable(argRows, 25)) |
| 476 | sections.push("") |
| 477 | } |
| 478 | |
| 479 | // Flags section |
| 480 | if (doc.flags.length > 0) { |
| 481 | sections.push(colors.bold("FLAGS")) |
| 482 | |
| 483 | const flagRows: Array<Row> = doc.flags.map((flag) => { |
| 484 | const names: Array<string> = [] |
| 485 | |
| 486 | // Add main name with -- prefix first |
| 487 | names.push(colors.green(`--${flag.name}`)) |
| 488 | |
| 489 | // Add aliases after (like -f) to match expected ordering |
| 490 | for (const alias of flag.aliases) { |
| 491 | names.push(colors.green(alias)) |
| 492 | } |
| 493 | |
| 494 | const namesPart = names.join(", ") |
no test coverage detected