Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-278.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Bare value-taking flags (e.g. `pluk send s --text hello`, `--run-dir /tmp/x`, `--filter x`) are now rejected with exit code 2 and a `--flag=<value>` hint instead of being parsed as the string `true` (which typed `true` into the agent pane); fixes #278.
12 changes: 11 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ ${ANSI_CYAN}Examples:${ANSI_RESET}
`);
}

const VALUE_FLAGS = new Set([
'text', 'session', 'run-dir', 'cli', 'command', 'cli-args', 'rebuttal',
'dir', 'rationguard-bin', 'patterns-dir', 'pane', 'filter',
]);

function parseArgs(args: string[]): { positional: string[]; flags: Record<string, string> } {
const positional: string[] = [];
const flags: Record<string, string> = {};
Expand All @@ -68,7 +73,12 @@ function parseArgs(args: string[]): { positional: string[]; flags: Record<string
if (eqIdx > 0) {
flags[arg.slice(2, eqIdx)] = arg.slice(eqIdx + 1);
} else {
flags[arg.slice(2)] = 'true';
const name = arg.slice(2);
if (VALUE_FLAGS.has(name)) {
console.error(`${paintStderr(ANSI_RED, 'Error:')} --${name} requires a value: use --${name}=<value>`);
process.exit(2);
}
flags[name] = 'true';
}
} else {
positional.push(arg);
Expand Down
21 changes: 21 additions & 0 deletions test/cli-error-paths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,24 @@ test('patterns --cli=unknown warns on stderr and lists available CLIs', () => {
assert.match(r.stderr, /no pattern set for nonesuch; available CLIs: .*omp/);
assert.match(r.stdout, /Patterns for nonesuch:/);
});

test('bare value-taking flags exit 2 with a --flag=<value> hint', () => {
for (const [args, flag] of [
[['send', 's', '--text', 'hello'], 'text'],
[['attach', 's', '--run-dir', '/x'], 'run-dir'],
[['subscribe', 's', '--filter', 'rate_limit'], 'filter'],
]) {
const r = spawnSync(process.execPath, [CLI, ...args], { encoding: 'utf8' });
assert.equal(r.status, 2, args.join(' '));
assert.match(r.stderr, new RegExp(`--${flag} requires a value: use --${flag}=<value>`));
}
});

test('bare boolean switches are still accepted', () => {
const r = spawnSync(process.execPath, [CLI, 'sessions', '--json'], {
encoding: 'utf8',
env: { ...process.env, PATH: `${stubBin}:${process.env.PATH}` },
});
assert.equal(r.status, 0);
assert.doesNotMatch(r.stderr, /requires a value/);
});
Loading