( command: string, args: string[], recursionDepth: number, wrapperCount: number, )
| 70 | } |
| 71 | |
| 72 | async function handleWrapper( |
| 73 | command: string, |
| 74 | args: string[], |
| 75 | recursionDepth: number, |
| 76 | wrapperCount: number, |
| 77 | ): Promise<string | null> { |
| 78 | const spec = await getCommandSpec(command) |
| 79 | |
| 80 | if (spec?.args) { |
| 81 | const commandArgIndex = toArray(spec.args).findIndex(arg => arg?.isCommand) |
| 82 | |
| 83 | if (commandArgIndex !== -1) { |
| 84 | const parts = [command] |
| 85 | |
| 86 | for (let i = 0; i < args.length && i <= commandArgIndex; i++) { |
| 87 | if (i === commandArgIndex) { |
| 88 | const result = await getCommandPrefixStatic( |
| 89 | args.slice(i).join(' '), |
| 90 | recursionDepth + 1, |
| 91 | wrapperCount + 1, |
| 92 | ) |
| 93 | if (result?.commandPrefix) { |
| 94 | parts.push(...result.commandPrefix.split(' ')) |
| 95 | return parts.join(' ') |
| 96 | } |
| 97 | break |
| 98 | } else if ( |
| 99 | args[i] && |
| 100 | !args[i]!.startsWith('-') && |
| 101 | !ENV_VAR.test(args[i]!) |
| 102 | ) { |
| 103 | parts.push(args[i]!) |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | const wrapped = args.find( |
| 110 | arg => !arg.startsWith('-') && !NUMERIC.test(arg) && !ENV_VAR.test(arg), |
| 111 | ) |
| 112 | if (!wrapped) return command |
| 113 | |
| 114 | const result = await getCommandPrefixStatic( |
| 115 | args.slice(args.indexOf(wrapped)).join(' '), |
| 116 | recursionDepth + 1, |
| 117 | wrapperCount + 1, |
| 118 | ) |
| 119 | |
| 120 | return !result?.commandPrefix ? null : `${command} ${result.commandPrefix}` |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Computes prefixes for a compound command (with && / || / ;). |
no test coverage detected