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

Function processArgs

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

Source from the content-addressed store, hash-verified

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

Callers 1

parseCommandLineFunction · 0.85

Calls 4

splitMethod · 0.80
execMethod · 0.80
mapMethod · 0.65
failMethod · 0.65

Tested by

no test coverage detected