| 742 | } |
| 743 | |
| 744 | const 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": { |