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

Function wizardInternal

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

Source from the content-addressed store, hash-verified

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

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