MCPcopy Index your code
hub / github.com/Effect-TS/effect / processArgs

Function processArgs

packages/cli/src/internal/options.ts:1686–1715  ·  view source on GitHub ↗
(
  args: ReadonlyArray<string>
)

Source from the content-addressed store, hash-verified

1684 * ["--option", "value"])
1685 */
1686const processArgs = (
1687 args: ReadonlyArray<string>
1688): Effect.Effect<ReadonlyArray<string>, ValidationError.ValidationError> =>
1689 Arr.matchLeft(args, {
1690 onEmpty: () => Effect.succeed(Arr.empty()),
1691 onNonEmpty: (head, tail) => {
1692 const value = head.trim()
1693 // Attempt to match clustered short command-line arguments (i.e. `-abc`)
1694 if (CLUSTERED_REGEX.test(value)) {
1695 const unclustered = value.substring(1).split("").map((c) => `-${c}`)
1696 return Effect.fail(InternalValidationError.unclusteredFlag(
1697 InternalHelpDoc.empty,
1698 unclustered,
1699 tail
1700 ))
1701 }
1702 // Attempt to match a long command-line argument and ensure the option and
1703 // it's value have been separated and added back to the arguments
1704 if (FLAG_REGEX.test(value)) {
1705 const result = FLAG_REGEX.exec(value)
1706 if (result !== null && result[2] !== undefined) {
1707 return Effect.succeed<ReadonlyArray<string>>(
1708 Arr.appendAll([result[1], result[2]], tail)
1709 )
1710 }
1711 }
1712 // Otherwise return the original command-line arguments
1713 return Effect.succeed(args)
1714 }
1715 })
1716
1717/**
1718 * Processes the command-line arguments for a parseable option, returning the

Callers 1

parseCommandLineFunction · 0.85

Calls 3

splitMethod · 0.80
mapMethod · 0.65
failMethod · 0.65

Tested by

no test coverage detected