1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tr should error out when if user provides more than 2 sets

Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
This commit is contained in:
Hanif Bin Ariffin 2021-07-09 23:22:12 +08:00
parent 2177b8dc37
commit db79b5abb2

View file

@ -235,7 +235,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.",
)
@ -259,7 +259,7 @@ 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<String> = match matches.values_of(options::SETS) {
let sets = match matches.values_of(options::SETS) {
Some(v) => v.map(|v| v.to_string()).collect(),
None => vec![],
};
@ -281,6 +281,15 @@ 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();