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

Function parseArgs

packages/effect/src/cli/internal/parser.ts:53–86  ·  view source on GitHub ↗
(
  lexResult: LexResult,
  command: Command.Any,
  commandPath: ReadonlyArray<string> = []
)

Source from the content-addressed store, hash-verified

51 * @internal
52 */
53export const parseArgs = (
54 lexResult: LexResult,
55 command: Command.Any,
56 commandPath: ReadonlyArray<string> = []
57): Effect.Effect<ParsedTokens, never, Environment> =>
58 Effect.gen(function*() {
59 const { tokens, trailingOperands: afterEndOfOptions } = lexResult
60 const newCommandPath = [...commandPath, command.name]
61 const result = scanCommandLevel(tokens, makeCommandContext(command, newCommandPath))
62
63 if (result._tag === "Leaf") {
64 return {
65 flags: result.flags,
66 arguments: [...result.arguments, ...afterEndOfOptions],
67 subcommand: Option.none(),
68 ...(result.errors.length > 0 && { errors: result.errors })
69 }
70 }
71
72 const subLex: LexResult = { tokens: result.childTokens, trailingOperands: afterEndOfOptions }
73 const subParsed = yield* parseArgs(
74 subLex,
75 result.sub,
76 newCommandPath
77 )
78
79 const allErrors = [...result.errors, ...(subParsed.errors ?? [])]
80 return {
81 flags: result.flags,
82 arguments: [],
83 subcommand: Option.some({ name: result.sub.name, parsedInput: subParsed }),
84 ...(allErrors.length > 0 && { errors: allErrors })
85 }
86 })
87
88/**
89 * Returns the subset of `tokens` left for the selected command once its

Callers 6

bin.tsFile · 0.85
run.tsFile · 0.85
run.mjsFile · 0.85
run.mjsFile · 0.85
run.mjsFile · 0.85
run.mjsFile · 0.85

Calls 3

scanCommandLevelFunction · 0.85
makeCommandContextFunction · 0.85
someMethod · 0.80

Tested by

no test coverage detected