( input: ReadonlyArray<string>, options: ReadonlyArray<ParseableInstruction>, config: CliConfig.CliConfig )
| 1597 | * first argument with its values if it corresponds to an option flag. |
| 1598 | */ |
| 1599 | const findOptions = ( |
| 1600 | input: ReadonlyArray<string>, |
| 1601 | options: ReadonlyArray<ParseableInstruction>, |
| 1602 | config: CliConfig.CliConfig |
| 1603 | ): Effect.Effect< |
| 1604 | [ |
| 1605 | ReadonlyArray<string>, |
| 1606 | ReadonlyArray<ParseableInstruction>, |
| 1607 | HashMap.HashMap<string, ReadonlyArray<string>> |
| 1608 | ], |
| 1609 | ValidationError.ValidationError |
| 1610 | > => |
| 1611 | Arr.matchLeft(options, { |
| 1612 | onEmpty: () => Effect.succeed([input, Arr.empty(), HashMap.empty()]), |
| 1613 | onNonEmpty: (head, tail) => |
| 1614 | parseCommandLine(head, input, config).pipe( |
| 1615 | Effect.flatMap(({ leftover, parsed }) => |
| 1616 | Option.match(parsed, { |
| 1617 | onNone: () => |
| 1618 | findOptions(leftover, tail, config).pipe(Effect.map(([nextArgs, nextOptions, map]) => |
| 1619 | [nextArgs, Arr.prepend(nextOptions, head), map] as [ |
| 1620 | ReadonlyArray<string>, |
| 1621 | ReadonlyArray<ParseableInstruction>, |
| 1622 | HashMap.HashMap<string, ReadonlyArray<string>> |
| 1623 | ] |
| 1624 | )), |
| 1625 | onSome: ({ name, values }) => |
| 1626 | Effect.succeed([leftover, tail, HashMap.make([name, values])] as [ |
| 1627 | ReadonlyArray<string>, |
| 1628 | ReadonlyArray<ParseableInstruction>, |
| 1629 | HashMap.HashMap<string, ReadonlyArray<string>> |
| 1630 | ]) |
| 1631 | }) |
| 1632 | ), |
| 1633 | Effect.catchTags({ |
| 1634 | CorrectedFlag: (e) => |
| 1635 | findOptions(input, tail, config).pipe( |
| 1636 | Effect.catchSome(() => Option.some(Effect.fail(e))), |
| 1637 | Effect.flatMap(([otherArgs, otherOptions, map]) => |
| 1638 | Effect.fail(e).pipe( |
| 1639 | Effect.when(() => HashMap.isEmpty(map)), |
| 1640 | Effect.as([otherArgs, Arr.prepend(otherOptions, head), map] as [ |
| 1641 | ReadonlyArray<string>, |
| 1642 | ReadonlyArray<ParseableInstruction>, |
| 1643 | HashMap.HashMap<string, ReadonlyArray<string>> |
| 1644 | ]) |
| 1645 | ) |
| 1646 | ) |
| 1647 | ), |
| 1648 | MissingFlag: () => |
| 1649 | findOptions(input, tail, config).pipe( |
| 1650 | Effect.map(([otherArgs, otherOptions, map]) => |
| 1651 | [otherArgs, Arr.prepend(otherOptions, head), map] as [ |
| 1652 | ReadonlyArray<string>, |
| 1653 | ReadonlyArray<ParseableInstruction>, |
| 1654 | HashMap.HashMap<string, ReadonlyArray<string>> |
| 1655 | ] |
| 1656 | ) |
no test coverage detected