( args: string[], spec: CommandSpec | null, )
| 69 | |
| 70 | // Find the first subcommand by skipping flags and their values |
| 71 | function findFirstSubcommand( |
| 72 | args: string[], |
| 73 | spec: CommandSpec | null, |
| 74 | ): string | undefined { |
| 75 | for (let i = 0; i < args.length; i++) { |
| 76 | const arg = args[i] |
| 77 | if (!arg) continue |
| 78 | if (arg.startsWith('-')) { |
| 79 | if (flagTakesArg(arg, args[i + 1], spec)) i++ |
| 80 | continue |
| 81 | } |
| 82 | if (!spec?.subcommands?.length) return arg |
| 83 | if (isKnownSubcommand(arg, spec)) return arg |
| 84 | } |
| 85 | return undefined |
| 86 | } |
| 87 | |
| 88 | export async function buildPrefix( |
| 89 | command: string, |
no test coverage detected