1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #2486 from hbina/hbina-tr-return-err-when-extra-args

`tr` should error out when if user provides more than 2 sets
This commit is contained in:
Sylvestre Ledru 2021-07-10 20:51:27 +02:00 committed by GitHub
commit 52c6593ef5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View file

@ -233,7 +233,7 @@ fn get_usage() -> String {
} }
fn get_long_usage() -> String { fn get_long_usage() -> String {
String::from( format!(
"Translate, squeeze, and/or delete characters from standard input, "Translate, squeeze, and/or delete characters from standard input,
writing to standard output.", 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 squeeze_flag = matches.is_present(options::SQUEEZE);
let truncate_flag = matches.is_present(options::TRUNCATE); let truncate_flag = matches.is_present(options::TRUNCATE);
let sets: Vec<String> = match matches.values_of(options::SETS) { let sets = matches
Some(v) => v.map(|v| v.to_string()).collect(), .values_of(options::SETS)
None => vec![], .map(|v| v.map(ToString::to_string).collect::<Vec<_>>())
}; .unwrap_or_default();
if sets.is_empty() { if sets.is_empty() {
show_error!( show_error!(
@ -350,5 +350,11 @@ pub fn uu_app() -> App<'static, 'static> {
.short("t") .short("t")
.help("first truncate SET1 to length of SET2"), .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),
)
} }

View file

@ -284,3 +284,11 @@ fn test_interpret_backslash_at_eol_literally() {
.succeeds() .succeeds()
.stdout_is("\\"); .stdout_is("\\");
} }
#[test]
fn test_more_than_2_sets() {
new_ucmd!()
.args(&["'abcdefgh'", "'a", "'b'"])
.pipe_in("hello world")
.fails();
}