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

Function findOptions

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

Source from the content-addressed store, hash-verified

1597 * first argument with its values if it corresponds to an option flag.
1598 */
1599const 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 )

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