MCPcopy
hub / github.com/Effect-TS/effect / getHelpInternal

Function getHelpInternal

packages/cli/src/internal/args.ts:493–567  ·  view source on GitHub ↗
(self: Instruction)

Source from the content-addressed store, hash-verified

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

Callers 2

getHelpFunction · 0.70
wizardInternalFunction · 0.70

Calls 4

StringInterface · 0.85
getMinSizeInternalFunction · 0.70
getMaxSizeInternalFunction · 0.70
textMethod · 0.45

Tested by

no test coverage detected