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

Function wizardInternal

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

Source from the content-addressed store, hash-verified

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