From c4c6819daea63fc32e641e83cfc5b3b9c5ccff19 Mon Sep 17 00:00:00 2001 From: Hanif Bin Ariffin Date: Fri, 9 Jul 2021 23:51:37 +0800 Subject: [PATCH] Reimplemented simply using args Signed-off-by: Hanif Bin Ariffin --- src/uu/tr/src/tr.rs | 16 ++++++---------- tests/by-util/test_tr.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 7df404f6f..1a696f3b9 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -281,15 +281,6 @@ pub fn uumain(args: impl uucore::Args) -> i32 { return 1; } - if sets.len() > 2 { - show_error!( - "extra operand '{}'\nTry `{} --help` for more information.", - sets[2], - executable!() - ); - return 1; - } - let stdin = stdin(); let mut locked_stdin = stdin.lock(); let stdout = stdout(); @@ -369,5 +360,10 @@ pub fn uu_app() -> App<'static, 'static> { .short("t") .help("first truncate SET1 to length of SET2"), ) - .arg(Arg::with_name(options::SETS).multiple(true)) + .arg( + Arg::with_name(options::SETS) + .multiple(true) + .takes_value(true) + .max_values(2), + ) } diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index 936af2ca8..4107fe87d 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -275,3 +275,11 @@ fn test_interpret_backslash_at_eol_literally() { .succeeds() .stdout_is("\\"); } + +#[test] +fn test_more_than_2_sets() { + new_ucmd!() + .args(&["'abcdefgh'", "'a", "'b'"]) + .pipe_in("hello world") + .fails(); +}