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