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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ tmux attach -t my-agent
| `pluk patterns --cli=claude` | Show loaded patterns for a CLI |
| `pluk <command> --help` / `-h` | Show usage (works after any subcommand) |

Unknown or misspelled `--flags` on any command exit 2 (`unknown flag --name`) instead of being silently ignored.

### Attach Flags

| Flag | What it does |
Expand Down
1 change: 1 addition & 0 deletions changelog.d/fixed-346.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `pluk` now rejects unknown or misspelled `--flags` (e.g. `--captur=50`, `--entr`) with an error (exit 2) instead of silently ignoring them.
13 changes: 13 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ const BOOL_FLAGS = new Set([
'no-open', 'dangerous', 'json', 'enter', 'literal',
]);

const KNOWN_FLAGS = new Set([
'help', ...VALUE_FLAGS, ...BOOL_FLAGS, 'capture', 'diagnostics',
]);

function rejectUnknownFlag(name: string): void {
if (!KNOWN_FLAGS.has(name)) {
console.error(`${paintStderr(ANSI_RED, 'Error:')} unknown flag --${name} (see pluk --help)`);
process.exit(2);
}
}

function parseArgs(args: string[]): { positional: string[]; flags: Record<string, string> } {
const positional: string[] = [];
const flags: Record<string, string> = {};
Expand All @@ -79,13 +90,15 @@ function parseArgs(args: string[]): { positional: string[]; flags: Record<string
if (eqIdx > 0) {
const name = arg.slice(2, eqIdx);
const value = arg.slice(eqIdx + 1);
rejectUnknownFlag(name);
if (BOOL_FLAGS.has(name) && value !== 'true' && value !== 'false') {
console.error(`${paintStderr(ANSI_RED, 'Error:')} --${name} is a boolean flag: use --${name} or --${name}=false`);
process.exit(2);
}
flags[name] = value;
} else {
const name = arg.slice(2);
rejectUnknownFlag(name);
if (VALUE_FLAGS.has(name)) {
console.error(`${paintStderr(ANSI_RED, 'Error:')} --${name} requires a value: use --${name}=<value>`);
process.exit(2);
Expand Down
13 changes: 13 additions & 0 deletions test/cli-error-paths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,16 @@ test('bare boolean switches are still accepted', () => {
assert.equal(r.status, 0);
assert.doesNotMatch(r.stderr, /requires a value/);
});

test('unknown or misspelled --flags exit 2 with an unknown-flag error', () => {
for (const [args, flag] of [
[['watch', 's', '--captur=50'], 'captur'],
[['send', 's', '--text=hi', '--entr'], 'entr'],
[['watch', 's', '--'], ''],
[['watch', 's', '--=x'], ''],
]) {
const r = spawnSync(process.execPath, [CLI, ...args], { encoding: 'utf8' });
assert.equal(r.status, 2, args.join(' '));
assert.match(r.stderr, new RegExp(`unknown flag --${flag}`));
}
});
Loading