MCPcopy Index your code
hub / github.com/Effect-TS/effect / wizardInternal

Function wizardInternal

packages/cli/src/internal/args.ts:904–1008  ·  view source on GitHub ↗
(self: Instruction, config: CliConfig.CliConfig)

Source from the content-addressed store, hash-verified

902}
903
904const wizardInternal = (self: Instruction, config: CliConfig.CliConfig): Effect.Effect<
905 Array<string>,
906 Terminal.QuitException | ValidationError.ValidationError,
907 FileSystem.FileSystem | Path.Path | Terminal.Terminal
908> => {
909 switch (self._tag) {
910 case "Empty": {
911 return Effect.succeed(Arr.empty())
912 }
913 case "Single": {
914 const help = getHelpInternal(self)
915 return InternalPrimitive.wizard(self.primitiveType, help).pipe(
916 Effect.zipLeft(Console.log()),
917 Effect.flatMap((input) => {
918 const args = Arr.of(input as string)
919 return validateInternal(self, args, config).pipe(Effect.as(args))
920 })
921 )
922 }
923 case "Map": {
924 return wizardInternal(self.args as Instruction, config).pipe(
925 Effect.tap((args) => validateInternal(self.args as Instruction, args, config))
926 )
927 }
928 case "Both": {
929 return Effect.zipWith(
930 wizardInternal(self.left as Instruction, config),
931 wizardInternal(self.right as Instruction, config),
932 (left, right) => Arr.appendAll(left, right)
933 ).pipe(Effect.tap((args) => validateInternal(self, args, config)))
934 }
935 case "Variadic": {
936 const repeatHelp = InternalHelpDoc.p(
937 "How many times should this argument should be repeated?"
938 )
939 const message = pipe(
940 getHelpInternal(self),
941 InternalHelpDoc.sequence(repeatHelp)
942 )
943 return InternalNumberPrompt.integer({
944 message: InternalHelpDoc.toAnsiText(message).trimEnd(),
945 min: getMinSizeInternal(self),
946 max: getMaxSizeInternal(self)
947 }).pipe(
948 Effect.zipLeft(Console.log()),
949 Effect.flatMap((n) =>
950 n <= 0
951 ? Effect.succeed(Arr.empty<string>())
952 : Ref.make(Arr.empty<string>()).pipe(
953 Effect.flatMap((ref) =>
954 wizardInternal(self.args as Instruction, config).pipe(
955 Effect.flatMap((args) => Ref.update(ref, Arr.appendAll(args))),
956 Effect.repeatN(n - 1),
957 Effect.zipRight(Ref.get(ref)),
958 Effect.tap((args) => validateInternal(self, args, config))
959 )
960 )
961 )

Callers 1

args.tsFile · 0.70

Calls 12

integerMethod · 0.80
getHelpInternalFunction · 0.70
validateInternalFunction · 0.70
pipeFunction · 0.70
getMinSizeInternalFunction · 0.70
getMaxSizeInternalFunction · 0.70
pipeMethod · 0.65
logMethod · 0.65
ofMethod · 0.65
makeMethod · 0.65
updateMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected