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

Function parseInternal

packages/cli/src/internal/commandDescriptor.ts:502–822  ·  view source on GitHub ↗
(
  self: Instruction,
  args: ReadonlyArray<string>,
  config: CliConfig.CliConfig
)

Source from the content-addressed store, hash-verified

500}
501
502const parseInternal = (
503 self: Instruction,
504 args: ReadonlyArray<string>,
505 config: CliConfig.CliConfig
506): Effect.Effect<
507 Directive.CommandDirective<any>,
508 ValidationError.ValidationError,
509 FileSystem.FileSystem | Path.Path | Terminal.Terminal
510> => {
511 const parseCommandLine = (
512 self: Standard | GetUserInput,
513 args: ReadonlyArray<string>
514 ): Effect.Effect<Array<string>, ValidationError.ValidationError> =>
515 Arr.matchLeft(args, {
516 onEmpty: () => {
517 const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
518 return Effect.fail(InternalValidationError.commandMismatch(error))
519 },
520 onNonEmpty: (head, tail) => {
521 const normalizedArgv0 = InternalCliConfig.normalizeCase(config, head)
522 const normalizedCommandName = InternalCliConfig.normalizeCase(config, self.name)
523 return Effect.succeed(tail).pipe(
524 Effect.when(() => normalizedArgv0 === normalizedCommandName),
525 Effect.flatten,
526 Effect.catchTag("NoSuchElementException", () => {
527 const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
528 return Effect.fail(InternalValidationError.commandMismatch(error))
529 })
530 )
531 }
532 })
533 switch (self._tag) {
534 case "Standard": {
535 const parseBuiltInArgs = (
536 args: ReadonlyArray<string>
537 ): Effect.Effect<
538 Directive.CommandDirective<never>,
539 ValidationError.ValidationError,
540 FileSystem.FileSystem | Path.Path | Terminal.Terminal
541 > =>
542 Arr.matchLeft(args, {
543 onEmpty: () => {
544 const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`)
545 return Effect.fail(InternalValidationError.commandMismatch(error))
546 },
547 onNonEmpty: (argv0) => {
548 const normalizedArgv0 = InternalCliConfig.normalizeCase(config, argv0)
549 const normalizedCommandName = InternalCliConfig.normalizeCase(config, self.name)
550 if (normalizedArgv0 === normalizedCommandName) {
551 const help = getHelpInternal(self, config)
552 const usage = getUsageInternal(self)
553 const options = InternalBuiltInOptions.builtInOptions(self, usage, help)
554 const argsWithoutCommand = Arr.drop(args, 1)
555 return InternalOptions.processCommandLine(options, argsWithoutCommand, config)
556 .pipe(
557 Effect.flatMap((tuple) => tuple[2]),
558 Effect.catchTag("NoSuchElementException", () => {
559 const error = InternalHelpDoc.p("No built-in option was matched")

Callers 2

loopFunction · 0.70

Calls 15

parseBuiltInArgsFunction · 0.85
parseUserDefinedArgsFunction · 0.85
exhaustiveSearchFunction · 0.85
getNamesInternalFunction · 0.85
getSubcommandsInternalFunction · 0.85
parseChildrenWithFunction · 0.85
spanMethod · 0.80
syncMethod · 0.80
headMethod · 0.80
parseCommandLineFunction · 0.70
getUsageInternalFunction · 0.70
getHelpInternalFunction · 0.70

Tested by

no test coverage detected