Repository navigation
Description
GNU diff accepts the side-by-side width as -W N, -WN, --width=N and --width N.
uutils only matches the single word --width=N, so -W 44 fails with
unrecognized option '-W' and --width 44 with unrecognized option '--width', both
exit 2. --tabsize N (separate argument) is rejected the same way. The GNU tests
side-by-side (-y -W 44) and side-by-side-seq (-yW 11, which also needs clustered
short options, #298) expose it.
Reproduction
printf 'x\n' > w1; printf 'y\n' > w2Rust (incorrect)
$ ./target/release/diffutils diff -y -W 20 w1 w2
unrecognized option '-W'
# Exit code: 2
$ ./target/release/diffutils diff -y --width 20 w1 w2
unrecognized option '--width'
# Exit code: 2
$ ./target/release/diffutils diff --tabsize 4 w1 w2
unrecognized option '--tabsize'
# Exit code: 2GNU (correct)
$ LC_ALL=C diff -y -W 20 w1 w2
x | y
# Exit code: 1
$ LC_ALL=C diff -y --width 20 w1 w2
x | y
# Exit code: 1
$ LC_ALL=C diff --tabsize 4 w1 w2
1c1
< x
---
> y
# Exit code: 1Root cause
Both options are recognized only through whole-word regexes in src/params.rs:119-120:
let tabsize_re = Regex::new(r"^--tabsize=(?<num>\d+)$").unwrap();
let width_re = Regex::new(r"^--width=(?P<long>\d+)$").unwrap();checked at src/params.rs:242 and src/params.rs:263. Anything else falls through to
unrecognized option at src/params.rs:324-326. option_argument/argument_value,
already used for -F and -S, handle all four spellings.
Test
Add to tests/by-util/test_diff.rs:
#[test]
fn width_option_forms() -> Result<(), Box<dyn std::error::Error>> {
let mut a = NamedTempFile::new()?;
a.write_all(b"x\n")?;
let mut b = NamedTempFile::new()?;
b.write_all(b"y\n")?;
for args in [
vec!["-W", "20"],
vec!["-W20"],
vec!["--width", "20"],
vec!["--width=20"],
] {
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.arg("diff").arg("-y").args(&args).arg(a.path()).arg(b.path());
cmd.assert()
.stderr(predicate::str::is_empty())
.stdout(predicate::str::starts_with("x "));
}
let mut cmd = cargo_bin_cmd!("diffutils");
cmd.arg("diff").args(["--tabsize", "4"]).arg(a.path()).arg(b.path());
cmd.assert().code(predicate::eq(1));
Ok(())
}Exposed by the GNU diffutils test suite: side-by-side, side-by-side-seq.
Activity
shadowmkj commentedon Nov 15, 2026
Why are we not using
clapfor command line parsing?GNU
diffalso supports-W10type of flags.I saw that uutils/coreutils is using clap with internal localization to parse the args seemlessly. Wouldn't it be better to implement a similar parser in this library?
This would resolve a lot of the current open issues that target argument parsing.
diff: accept -W N, -WN, --width N and --tabsize N option forms (uutil…