From dc664006feb59a67e674ac59cb09d380f5e21991 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Fri, 23 Feb 2024 02:24:02 +0100 Subject: [PATCH] tr: enable passing -d multiple times --- src/uu/tr/src/tr.rs | 3 ++- tests/by-util/test_tr.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 8b66d360c..ec3fc6763 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -179,7 +179,8 @@ pub fn uu_app() -> Command { .short('d') .long(options::DELETE) .help("delete characters in SET1, do not translate") - .action(ArgAction::SetTrue), + .action(ArgAction::SetTrue) + .overrides_with(options::DELETE), ) .arg( Arg::new(options::SQUEEZE) diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index 1086dee6a..da55daa1c 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -46,6 +46,32 @@ fn test_delete() { .stdout_is("BD"); } +#[test] +fn test_delete_afterwards_is_not_flag() { + new_ucmd!() + .args(&["a-z", "-d"]) + .pipe_in("aBcD") + .succeeds() + .stdout_is("-BdD"); +} + +#[test] +fn test_delete_multi() { + new_ucmd!() + .args(&["-d", "-d", "a-z"]) + .pipe_in("aBcD") + .succeeds() + .stdout_is("BD"); +} + +#[test] +fn test_delete_late() { + new_ucmd!() + .args(&["-d", "a-z", "-d"]) + .fails() + .stderr_contains("extra operand '-d'"); +} + #[test] fn test_delete_complement() { new_ucmd!()