(self: Instruction, config: CliConfig.CliConfig)
| 1371 | } |
| 1372 | |
| 1373 | const 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( |
no test coverage detected