( command: string, abortSignal: AbortSignal, isNonInteractiveSession: boolean, getPrefix: ReturnType<typeof createCommandPrefixExtractor>, splitCommandFn: (command: string) => string[] | Promise<string[]>, )
| 330 | } |
| 331 | |
| 332 | async function getCommandSubcommandPrefixImpl( |
| 333 | command: string, |
| 334 | abortSignal: AbortSignal, |
| 335 | isNonInteractiveSession: boolean, |
| 336 | getPrefix: ReturnType<typeof createCommandPrefixExtractor>, |
| 337 | splitCommandFn: (command: string) => string[] | Promise<string[]>, |
| 338 | ): Promise<CommandSubcommandPrefixResult | null> { |
| 339 | const subcommands = await splitCommandFn(command) |
| 340 | |
| 341 | const [fullCommandPrefix, ...subcommandPrefixesResults] = await Promise.all([ |
| 342 | getPrefix(command, abortSignal, isNonInteractiveSession), |
| 343 | ...subcommands.map(async subcommand => ({ |
| 344 | subcommand, |
| 345 | prefix: await getPrefix(subcommand, abortSignal, isNonInteractiveSession), |
| 346 | })), |
| 347 | ]) |
| 348 | |
| 349 | if (!fullCommandPrefix) { |
| 350 | return null |
| 351 | } |
| 352 | |
| 353 | const subcommandPrefixes = subcommandPrefixesResults.reduce( |
| 354 | (acc, { subcommand, prefix }) => { |
| 355 | if (prefix) { |
| 356 | acc.set(subcommand, prefix) |
| 357 | } |
| 358 | return acc |
| 359 | }, |
| 360 | new Map<string, CommandPrefixResult>(), |
| 361 | ) |
| 362 | |
| 363 | return { |
| 364 | ...fullCommandPrefix, |
| 365 | subcommandPrefixes, |
| 366 | } |
| 367 | } |
no test coverage detected