MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getCommandPrefixStatic

Function getCommandPrefixStatic

src/utils/bash/prefix.ts:28–70  ·  view source on GitHub ↗
(
  command: string,
  recursionDepth = 0,
  wrapperCount = 0,
)

Source from the content-addressed store, hash-verified

26}
27
28export async function getCommandPrefixStatic(
29 command: string,
30 recursionDepth = 0,
31 wrapperCount = 0,
32): Promise<{ commandPrefix: string | null } | null> {
33 if (wrapperCount > 2 || recursionDepth > 10) return null
34
35 const parsed = await parseCommand(command)
36 if (!parsed) return null
37 if (!parsed.commandNode) {
38 return { commandPrefix: null }
39 }
40
41 const { envVars, commandNode } = parsed
42 const cmdArgs = extractCommandArguments(commandNode)
43
44 const [cmd, ...args] = cmdArgs
45 if (!cmd) return { commandPrefix: null }
46
47 // Check if this is a wrapper command by looking at its spec
48 const spec = await getCommandSpec(cmd)
49 // Check if this is a wrapper command
50 let isWrapper =
51 WRAPPER_COMMANDS.has(cmd) ||
52 (spec?.args && toArray(spec.args).some(arg => arg?.isCommand))
53
54 // Special case: if the command has subcommands and the first arg matches a subcommand,
55 // treat it as a regular command, not a wrapper
56 if (isWrapper && args[0] && isKnownSubcommand(args[0], spec)) {
57 isWrapper = false
58 }
59
60 const prefix = isWrapper
61 ? await handleWrapper(cmd, args, recursionDepth, wrapperCount)
62 : await buildPrefix(cmd, args, spec)
63
64 if (prefix === null && recursionDepth === 0 && isWrapper) {
65 return null
66 }
67
68 const envPrefix = envVars.length ? `${envVars.join(' ')} ` : ''
69 return { commandPrefix: prefix ? envPrefix + prefix : null }
70}
71
72async function handleWrapper(
73 command: string,

Callers 2

handleWrapperFunction · 0.70

Calls 7

extractCommandArgumentsFunction · 0.85
handleWrapperFunction · 0.85
buildPrefixFunction · 0.85
parseCommandFunction · 0.70
toArrayFunction · 0.70
isKnownSubcommandFunction · 0.70
hasMethod · 0.45

Tested by

no test coverage detected