Summary: cac 7.0 fails to match multi-word commands when parsing argv that includes their second word + positional args. The commands appear correctly in --help, so registration works — only matching is broken.
Repro (Node 22, cac 7.0.0):
import { cac } from 'cac';
const cli = cac('test');
cli.command('creds set <account>', 'set').action((account) => {
console.log('SET match', account);
});
cli.command('creds get <account>', 'get').action((account) => {
console.log('GET match', account);
});
cli.parse(['node', 'test', 'creds', 'get', 'foo'], { run: false });
console.log('matched name:', cli.matchedCommand?.name);
await cli.runMatchedCommand();
Expected: matchedCommand.name is creds get, action runs and prints GET match foo.
Actual: matchedCommand is undefined. No action fires.
--help correctly lists both creds set and creds get as separate commands, so registration is fine. The bug is in the matcher: it treats the second word (get) as a positional arg of the first command rather than part of the command name.
Workaround: register a single command creds <action> [target] and dispatch on <action> inside the handler. Functional from the user's perspective (mytool creds get foo still works) but a real gap.
Happy to PR a fix if useful — wanted to file before patching to avoid duplicate work.
Environment: Windows 10, Node v24.15.0, cac 7.0.0
Summary: cac 7.0 fails to match multi-word commands when parsing argv that includes their second word + positional args. The commands appear correctly in
--help, so registration works — only matching is broken.Repro (Node 22, cac 7.0.0):
Expected:
matchedCommand.nameiscreds get, action runs and printsGET match foo.Actual:
matchedCommandisundefined. No action fires.--helpcorrectly lists bothcreds setandcreds getas separate commands, so registration is fine. The bug is in the matcher: it treats the second word (get) as a positional arg of the first command rather than part of the command name.Workaround: register a single command
creds <action> [target]and dispatch on<action>inside the handler. Functional from the user's perspective (mytool creds get foostill works) but a real gap.Happy to PR a fix if useful — wanted to file before patching to avoid duplicate work.
Environment: Windows 10, Node v24.15.0, cac 7.0.0