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