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

Function findOptions

packages/cli/src/internal/options.ts:1600–1665  ·  view source on GitHub ↗
(
  input: ReadonlyArray<string>,
  options: ReadonlyArray<ParseableInstruction>,
  config: CliConfig.CliConfig
)

Source from the content-addressed store, hash-verified

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

Callers 2

matchOptionsFunction · 0.85
matchUnclusteredFunction · 0.85

Calls 7

matchUnclusteredFunction · 0.85
parseCommandLineFunction · 0.70
pipeMethod · 0.65
mapMethod · 0.65
makeMethod · 0.65
failMethod · 0.65
isEmptyMethod · 0.65

Tested by

no test coverage detected