diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index 2abc652ff..45a3027b2 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -233,7 +233,7 @@ fn get_usage() -> String { } fn get_long_usage() -> String { - String::from( + format!( "Translate, squeeze, and/or delete characters from standard input, writing to standard output.", ) @@ -257,10 +257,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let squeeze_flag = matches.is_present(options::SQUEEZE); let truncate_flag = matches.is_present(options::TRUNCATE); - let sets: Vec = match matches.values_of(options::SETS) { - Some(v) => v.map(|v| v.to_string()).collect(), - None => vec![], - }; + let sets = matches + .values_of(options::SETS) + .map(|v| v.map(ToString::to_string).collect::>()) + .unwrap_or_default(); if sets.is_empty() { show_error!( @@ -350,5 +350,11 @@ 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) + .min_values(1) + .max_values(2), + ) } diff --git a/tests/by-util/test_tr.rs b/tests/by-util/test_tr.rs index 07e3a843e..8a3e36625 100644 --- a/tests/by-util/test_tr.rs +++ b/tests/by-util/test_tr.rs @@ -284,3 +284,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(); +}