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

Function validateInternal

packages/cli/src/internal/args.ts:744–862  ·  view source on GitHub ↗
(
  self: Instruction,
  args: ReadonlyArray<string>,
  config: CliConfig.CliConfig
)

Source from the content-addressed store, hash-verified

742}
743
744const validateInternal = (
745 self: Instruction,
746 args: ReadonlyArray<string>,
747 config: CliConfig.CliConfig
748): Effect.Effect<
749 [Array<string>, any],
750 ValidationError.ValidationError,
751 FileSystem.FileSystem | Path.Path | Terminal.Terminal
752> => {
753 switch (self._tag) {
754 case "Empty": {
755 return Effect.succeed([args as Array<string>, undefined])
756 }
757 case "Single": {
758 return Effect.suspend(() => {
759 return Arr.matchLeft(args, {
760 onEmpty: () => {
761 const choices = InternalPrimitive.getChoices(self.primitiveType)
762 if (Option.isSome(self.pseudoName) && Option.isSome(choices)) {
763 return Effect.fail(InternalValidationError.missingValue(InternalHelpDoc.p(
764 `Missing argument <${self.pseudoName.value}> with choices ${choices.value}`
765 )))
766 }
767 if (Option.isSome(self.pseudoName)) {
768 return Effect.fail(InternalValidationError.missingValue(InternalHelpDoc.p(
769 `Missing argument <${self.pseudoName.value}>`
770 )))
771 }
772 if (Option.isSome(choices)) {
773 return Effect.fail(InternalValidationError.missingValue(InternalHelpDoc.p(
774 `Missing argument ${InternalPrimitive.getTypeName(self.primitiveType)} with choices ${choices.value}`
775 )))
776 }
777 return Effect.fail(InternalValidationError.missingValue(InternalHelpDoc.p(
778 `Missing argument ${InternalPrimitive.getTypeName(self.primitiveType)}`
779 )))
780 },
781 onNonEmpty: (head, tail) =>
782 InternalPrimitive.validate(self.primitiveType, Option.some(head), config).pipe(
783 Effect.mapBoth({
784 onFailure: (text) => InternalValidationError.invalidArgument(InternalHelpDoc.p(text)),
785 onSuccess: (a) => [tail, a]
786 })
787 )
788 })
789 })
790 }
791 case "Map": {
792 return validateInternal(self.args as Instruction, args, config).pipe(
793 Effect.flatMap(([leftover, a]) =>
794 Effect.matchEffect(self.f(a), {
795 onFailure: (doc) => Effect.fail(InternalValidationError.invalidArgument(doc)),
796 onSuccess: (b) => Effect.succeed([leftover, b])
797 })
798 )
799 )
800 }
801 case "Both": {

Callers 3

args.tsFile · 0.70
loopFunction · 0.70
wizardInternalFunction · 0.70

Calls 7

StringInterface · 0.85
validateMethod · 0.80
loopFunction · 0.70
failMethod · 0.65
pipeMethod · 0.65
fMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…