Skip to content

Multi-word commands not matched at parse time (only listed in --help) #170

Description

@christianjensenv

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.

matched name: undefined

--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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions