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

Function wizardInternal

packages/cli/src/internal/options.ts:1373–1532  ·  view source on GitHub ↗
(self: Instruction, config: CliConfig.CliConfig)

Source from the content-addressed store, hash-verified

1371}
1372
1373const wizardInternal = (self: Instruction, config: CliConfig.CliConfig): Effect.Effect<
1374 Array<string>,
1375 Terminal.QuitException | ValidationError.ValidationError,
1376 FileSystem.FileSystem | Path.Path | Terminal.Terminal
1377> => {
1378 switch (self._tag) {
1379 case "Empty": {
1380 return Effect.succeed(Arr.empty())
1381 }
1382 case "Single": {
1383 const help = getHelpInternal(self)
1384 return InternalPrimitive.wizard(self.primitiveType, help).pipe(
1385 Effect.flatMap((input) => {
1386 // There will always be at least one name in names
1387 const args = Arr.make(getNames(self)[0]!, input as string)
1388 return parseCommandLine(self, args, config).pipe(Effect.as(args))
1389 }),
1390 Effect.zipLeft(Console.log())
1391 )
1392 }
1393 case "KeyValueMap": {
1394 const message = InternalHelpDoc.p("Enter `key=value` pairs separated by spaces")
1395 return InternalListPrompt.list({
1396 message: InternalHelpDoc.toAnsiText(message).trim(),
1397 delimiter: " "
1398 }).pipe(
1399 Effect.flatMap((args) => {
1400 const identifier = Option.getOrElse(getIdentifierInternal(self), () => "")
1401 return parseInternal(self, HashMap.make([identifier, args]), config).pipe(
1402 Effect.as(Arr.prepend(args, identifier))
1403 )
1404 }),
1405 Effect.zipLeft(Console.log())
1406 )
1407 }
1408 case "Map": {
1409 return wizardInternal(self.options as Instruction, config)
1410 }
1411 case "Both": {
1412 return Effect.zipWith(
1413 wizardInternal(self.left as Instruction, config),
1414 wizardInternal(self.right as Instruction, config),
1415 (left, right) => Arr.appendAll(left, right)
1416 )
1417 }
1418 case "OrElse": {
1419 const alternativeHelp = InternalHelpDoc.p("Select which option you would like to use")
1420 const message = pipe(
1421 getHelpInternal(self),
1422 InternalHelpDoc.sequence(alternativeHelp)
1423 )
1424 const makeChoice = (title: string, value: Instruction) => ({ title, value })
1425 const choices = Arr.getSomes([
1426 Option.map(
1427 getIdentifierInternal(self.left as Instruction),
1428 (title) => makeChoice(title, self.left as Instruction)
1429 ),
1430 Option.map(

Callers 1

options.tsFile · 0.70

Calls 15

isBoolInternalFunction · 0.85
integerMethod · 0.80
getHelpInternalFunction · 0.70
getNamesFunction · 0.70
parseCommandLineFunction · 0.70
getIdentifierInternalFunction · 0.70
parseInternalFunction · 0.70
pipeFunction · 0.70
makeChoiceFunction · 0.70
getMinSizeInternalFunction · 0.70
getMaxSizeInternalFunction · 0.70
pipeMethod · 0.65

Tested by

no test coverage detected