(self: Instruction, config: CliConfig.CliConfig)
| 325 | // ============================================================================= |
| 326 | |
| 327 | const getHelpInternal = (self: Instruction, config: CliConfig.CliConfig): HelpDoc.HelpDoc => { |
| 328 | switch (self._tag) { |
| 329 | case "Standard": { |
| 330 | const header = InternalHelpDoc.isEmpty(self.description) |
| 331 | ? InternalHelpDoc.empty |
| 332 | : InternalHelpDoc.sequence(InternalHelpDoc.h1("DESCRIPTION"), self.description) |
| 333 | const argsHelp = InternalArgs.getHelp(self.args) |
| 334 | const argsSection = InternalHelpDoc.isEmpty(argsHelp) |
| 335 | ? InternalHelpDoc.empty |
| 336 | : InternalHelpDoc.sequence(InternalHelpDoc.h1("ARGUMENTS"), argsHelp) |
| 337 | const options = config.showBuiltIns |
| 338 | ? Options.all([self.options, InternalBuiltInOptions.builtIns]) |
| 339 | : self.options |
| 340 | const optionsHelp = InternalOptions.getHelp(options) |
| 341 | const optionsSection = InternalHelpDoc.isEmpty(optionsHelp) |
| 342 | ? InternalHelpDoc.empty |
| 343 | : InternalHelpDoc.sequence(InternalHelpDoc.h1("OPTIONS"), optionsHelp) |
| 344 | return InternalHelpDoc.sequence(header, InternalHelpDoc.sequence(argsSection, optionsSection)) |
| 345 | } |
| 346 | case "GetUserInput": { |
| 347 | return InternalHelpDoc.isEmpty(self.description) |
| 348 | ? InternalHelpDoc.empty |
| 349 | : InternalHelpDoc.sequence(InternalHelpDoc.h1("DESCRIPTION"), self.description) |
| 350 | } |
| 351 | case "Map": { |
| 352 | return getHelpInternal(self.command, config) |
| 353 | } |
| 354 | case "Subcommands": { |
| 355 | const getUsage = ( |
| 356 | command: Instruction, |
| 357 | preceding: ReadonlyArray<Span.Span> |
| 358 | ): ReadonlyArray<[Span.Span, Span.Span]> => { |
| 359 | switch (command._tag) { |
| 360 | case "Standard": |
| 361 | case "GetUserInput": { |
| 362 | const usage = InternalHelpDoc.getSpan(InternalUsage.getHelp(getUsageInternal(command))) |
| 363 | const usages = Arr.append(preceding, usage) |
| 364 | const finalUsage = Arr.reduce( |
| 365 | usages, |
| 366 | InternalSpan.empty, |
| 367 | (acc, next) => |
| 368 | InternalSpan.isText(acc) && acc.value === "" |
| 369 | ? next |
| 370 | : InternalSpan.isText(next) && next.value === "" |
| 371 | ? acc |
| 372 | : InternalSpan.spans([acc, InternalSpan.space, next]) |
| 373 | ) |
| 374 | const description = InternalHelpDoc.getSpan(command.description) |
| 375 | return Arr.of([finalUsage, description]) |
| 376 | } |
| 377 | case "Map": { |
| 378 | return getUsage(command.command, preceding) |
| 379 | } |
| 380 | case "Subcommands": { |
| 381 | const parentUsage = getUsage(command.parent, preceding) |
| 382 | return Option.match(Arr.head(parentUsage), { |
| 383 | onNone: () => |
| 384 | Arr.flatMap( |
no test coverage detected