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

Function parseInternal

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

Source from the content-addressed store, hash-verified

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