MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / resolveCommand

Function resolveCommand

packages/codex-native-api/src/default_provider.ts:483–521  ·  view source on GitHub ↗
(
  command: string,
  {
    platform = process.platform,
    env = process.env,
    cwd = process.cwd(),
  }: {
    platform?: NodeJS.Platform;
    env?: NodeJS.ProcessEnv;
    cwd?: string;
  } = {},
)

Source from the content-addressed store, hash-verified

481}
482
483function resolveCommand(
484 command: string,
485 {
486 platform = process.platform,
487 env = process.env,
488 cwd = process.cwd(),
489 }: {
490 platform?: NodeJS.Platform;
491 env?: NodeJS.ProcessEnv;
492 cwd?: string;
493 } = {},
494): string | null {
495 const normalizedCommand = normalizeOptionalString(command);
496 if (!normalizedCommand) {
497 return null;
498 }
499 const explicit = resolveExplicitCommandPath(normalizedCommand, {
500 platform,
501 env,
502 cwd,
503 });
504 if (explicit) {
505 return explicit;
506 }
507 if (hasPathSeparator(normalizedCommand)) {
508 return null;
509 }
510 const pathEntries = splitPathEntries(env.PATH ?? '');
511 const suffixes = resolveCommandSuffixes(platform, env, normalizedCommand);
512 for (const entry of pathEntries) {
513 for (const suffix of suffixes) {
514 const candidate = path.join(entry, `${normalizedCommand}${suffix}`);
515 if (isCommandFile(candidate)) {
516 return candidate;
517 }
518 }
519 }
520 return null;
521}
522
523function resolveExplicitCommandPath(
524 command: string,

Callers 1

Calls 6

normalizeOptionalStringFunction · 0.85
hasPathSeparatorFunction · 0.70
splitPathEntriesFunction · 0.70
resolveCommandSuffixesFunction · 0.70
isCommandFileFunction · 0.70

Tested by

no test coverage detected