MCPcopy Create free account
hub / github.com/Effect-TS/effect / validateInternal

Function validateInternal

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

Source from the content-addressed store, hash-verified

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