Skip to content

diff: add the program name and --help hint to the extra operand error - #368

Merged
sylvestre merged 1 commit into
uutils:mainfrom
nurlanmnn:fix-extra-operand-dashdash-355
Nov 10, 2026
Merged

sylvestre merged 1 commit into
uutils:mainfrom
nurlanmnn:fix-extra-operand-dashdash-355

Conversation

@nurlanmnn

@nurlanmnn nurlanmnn commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #355.

Follow-up to 0567e1c, which rejects extra operands but prints a bare extra operand 'X'. The error now reads diff: extra operand 'X' followed by diff: Try 'diff --help' for more information., on all three paths, using the executable name for both. Exit code is still 2. Added extra_operand_without_double_dash (exit code 2, empty stdout, exact message).

This change was written with AI assistance (Codex/Cursor) and I reviewed the diff and ran the checks myself; the implementation is written from the issue description, not derived from GNU source.

🤖 Generated with Claude Code

Comment thread src/params.rs Outdated
params.executable.to_string_lossy()
));
};
if let Some((_, extra)) = opts.next() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without --, diff a b c still says "Usage: diff "
the issue covers that case too, could you please use the same extra operand message there?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: diff a b c now gets the same extra operand error as the -- case.

Comment thread src/params.rs Outdated
if let Some((_, extra)) = opts.next() {
let exe = params.executable.to_string_lossy();
return Err(format!(
"{exe}: extra operand '{}'\n{exe}: Try 'diff --help' for more information.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why hardcode 'diff --help' when exe is used for the prefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it now uses exe for the --help hint too.

Comment thread src/params.rs Outdated
);
}
#[test]
fn extra_operand_after_double_dash() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a test in tests/integration.rs too (exit code 2, empty stdout), and one for the case without --

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added extra_operand_without_double_dash in tests/by-util/test_diff.rs (exit code 2, empty stdout, exact message). extra_operand_after_double_dash, now on main, covers the -- case the same way. I put them there because tests/integration.rs no longer exists on main.

Report "extra operand" with the --help hint and exit 2 instead of silently ignoring them. Fixes uutils#355.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@nurlanmnn
nurlanmnn force-pushed the fix-extra-operand-dashdash-355 branch from bf785bd to 090810c Compare November 9, 2026 21:33
@nurlanmnn nurlanmnn changed the title diff: reject extra operands after the first two, including after -- diff: add the program name and --help hint to the extra operand error Nov 9, 2026
@sylvestre
sylvestre merged commit 8ffca72 into uutils:main Nov 10, 2026
31 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

diff - extra operands after -- are silently ignored

2 participants