Observed behavior
parseArgs short-circuits when either --help or --version is present and returns immediately, before the positional.length > 1 check that was added to reject extra positional arguments (see #33). As a result:
parseArgs(['--help']) -> { help: true, ... } (OK)
parseArgs(['--help', 'foo', 'bar']) -> { help: true, ... } (silently ignores foo, bar)
parseArgs(['--version', 'extra1', 'extra2']) -> { version: true, ... } (silently ignores extras)
parseArgs(['config.json', 'extra']) -> THROW: Unexpected extra arguments: extra (correct)
The relevant block in parseArgs:
if (booleans.help || booleans.version) {
return {
help: booleans.help,
version: booleans.version,
verbose: booleans.verbose,
dryRun: booleans.dryRun,
maxPrompts,
};
}
if (positional.length > 1) {
throw new Error(
`Unexpected extra arguments: ${positional.slice(1).join(' ')}`,
);
}
Expected behavior
For consistency with #33's fix, --help and --version should also reject extra positional arguments (or at least reject anything beyond a single positional). Silent acceptance hides typos like loop-the-loop --help confg.json and is inconsistent with the rest of the parser's strictness.
Minimal reproduction
parseArgs(['--help', 'foo', 'bar']);
// Returns { help: true, ... } with no warning that 'foo' and 'bar' were dropped.
Suggested fix
Move the positional.length > 1 check (or a positional.length > 0 check for the help/version branch) above the help/version short-circuit, or duplicate it inside the branch. For example:
if (booleans.help || booleans.version) {
if (positional.length > 0) {
throw new Error(
`Unexpected extra arguments: ${positional.join(' ')}`,
);
}
return { help: booleans.help, version: booleans.version, ... };
}
This mirrors how the parser already treats trailing args after a config path.
Observed behavior
parseArgsshort-circuits when either--helpor--versionis present and returns immediately, before thepositional.length > 1check that was added to reject extra positional arguments (see #33). As a result:The relevant block in
parseArgs:Expected behavior
For consistency with #33's fix,
--helpand--versionshould also reject extra positional arguments (or at least reject anything beyond a single positional). Silent acceptance hides typos likeloop-the-loop --help confg.jsonand is inconsistent with the rest of the parser's strictness.Minimal reproduction
Suggested fix
Move the
positional.length > 1check (or apositional.length > 0check for the help/version branch) above the help/version short-circuit, or duplicate it inside the branch. For example:This mirrors how the parser already treats trailing args after a config path.