From 67e88c16e3ce5e6f6f22679cbc6801ed00705e07 Mon Sep 17 00:00:00 2001 From: Coro Date: Thu, 13 Aug 2026 10:11:52 -0600 Subject: [PATCH] uniq: accept a repeated -D/--all-repeated, last one wins GNU uniq accepts -D/--all-repeated given more than once and uses the last occurrence. clap rejected the second one, so a script mixing the short -D and the long --all-repeated form failed with "cannot be used multiple times". Add overrides_with so a repeat overrides the earlier value instead of erroring. --- src/uu/uniq/src/uniq.rs | 4 +++- tests/by-util/test_uniq.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/uu/uniq/src/uniq.rs b/src/uu/uniq/src/uniq.rs index 6037a662249..38f6b146945 100644 --- a/src/uu/uniq/src/uniq.rs +++ b/src/uu/uniq/src/uniq.rs @@ -723,7 +723,9 @@ pub fn uu_app() -> Command { .value_name("delimit-method") .num_args(0..=1) .default_missing_value("none") - .require_equals(true), + .require_equals(true) + // GNU accepts a repeated -D/--all-repeated and uses the last one. + .overrides_with(options::ALL_REPEATED), ) .arg( Arg::new(options::GROUP) diff --git a/tests/by-util/test_uniq.rs b/tests/by-util/test_uniq.rs index 8e940a743cd..58a9bff062b 100644 --- a/tests/by-util/test_uniq.rs +++ b/tests/by-util/test_uniq.rs @@ -162,6 +162,22 @@ fn test_stdin_all_repeated() { .stdout_is_fixture("sorted-all-repeated.expected"); } +#[test] +fn test_all_repeated_repeated_last_wins() { + // GNU uniq accepts a repeated -D/--all-repeated and uses the last occurrence, + // instead of rejecting the second one. + new_ucmd!() + .args(&["-D", "--all-repeated=separate"]) + .pipe_in("a\na\nb\nb\nc\n") + .succeeds() + .stdout_is("a\na\n\nb\nb\n"); + new_ucmd!() + .args(&["-D", "-D"]) + .pipe_in("a\na\n") + .succeeds() + .stdout_is("a\na\n"); +} + #[test] fn test_all_repeated_followed_by_filename() { let filename = "test.txt";