(self: Instruction)
| 492 | } |
| 493 | |
| 494 | const getHelpInternal = (self: Instruction): HelpDoc.HelpDoc => { |
| 495 | switch (self._tag) { |
| 496 | case "Empty": { |
| 497 | return InternalHelpDoc.empty |
| 498 | } |
| 499 | case "Single": { |
| 500 | return InternalHelpDoc.descriptionList([[ |
| 501 | InternalSpan.weak(self.name), |
| 502 | InternalHelpDoc.sequence( |
| 503 | InternalHelpDoc.p(InternalPrimitive.getHelp(self.primitiveType)), |
| 504 | self.description |
| 505 | ) |
| 506 | ]]) |
| 507 | } |
| 508 | case "Map": { |
| 509 | return getHelpInternal(self.args as Instruction) |
| 510 | } |
| 511 | case "Both": { |
| 512 | return InternalHelpDoc.sequence( |
| 513 | getHelpInternal(self.left as Instruction), |
| 514 | getHelpInternal(self.right as Instruction) |
| 515 | ) |
| 516 | } |
| 517 | case "Variadic": { |
| 518 | const help = getHelpInternal(self.args as Instruction) |
| 519 | return InternalHelpDoc.mapDescriptionList(help, (oldSpan, oldBlock) => { |
| 520 | const min = getMinSizeInternal(self as Instruction) |
| 521 | const max = getMaxSizeInternal(self as Instruction) |
| 522 | const newSpan = InternalSpan.text( |
| 523 | Option.isSome(self.max) ? ` ${min} - ${max}` : min === 0 ? "..." : ` ${min}+` |
| 524 | ) |
| 525 | const newBlock = InternalHelpDoc.p( |
| 526 | Option.isSome(self.max) |
| 527 | ? `This argument must be repeated at least ${min} times and may be repeated up to ${max} times.` |
| 528 | : min === 0 |
| 529 | ? "This argument may be repeated zero or more times." |
| 530 | : `This argument must be repeated at least ${min} times.` |
| 531 | ) |
| 532 | return [InternalSpan.concat(oldSpan, newSpan), InternalHelpDoc.sequence(oldBlock, newBlock)] |
| 533 | }) |
| 534 | } |
| 535 | case "WithDefault": { |
| 536 | return InternalHelpDoc.mapDescriptionList( |
| 537 | getHelpInternal(self.args as Instruction), |
| 538 | (span, block) => { |
| 539 | const optionalDescription = Option.isOption(self.fallback) |
| 540 | ? Option.match(self.fallback, { |
| 541 | onNone: () => InternalHelpDoc.p("This setting is optional."), |
| 542 | onSome: (fallbackValue) => { |
| 543 | const inspectableValue = Predicate.isObject(fallbackValue) ? fallbackValue : String(fallbackValue) |
| 544 | const displayValue = Inspectable.toStringUnknown(inspectableValue, 0) |
| 545 | return InternalHelpDoc.p(`This setting is optional. Defaults to: ${displayValue}`) |
| 546 | } |
| 547 | }) |
| 548 | : InternalHelpDoc.p("This setting is optional.") |
| 549 | return [span, InternalHelpDoc.sequence(block, optionalDescription)] |
| 550 | } |
| 551 | ) |
no test coverage detected