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