From 9e029f542be14c6528e7ff8257cc7350947f6068 Mon Sep 17 00:00:00 2001 From: Will Shuttleworth Date: Tue, 1 Jul 2025 12:14:46 -0400 Subject: [PATCH] stty: add min and time settings --- src/uu/stty/src/stty.rs | 38 +++++++++++++++++++++++++++++++++++++- tests/by-util/test_stty.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index b811e084e..ca488ac86 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -319,7 +319,43 @@ fn stty(opts: &Options) -> UResult<()> { )); } } - // baud rate setting + } else if *arg == "min" { + match args_iter.next() { + Some(min) => match parse_u8_or_err(min) { + Ok(n) => { + valid_args + .push(ArgOptions::Mapping((SpecialCharacterIndices::VMIN, n))); + } + Err(e) => return Err(USimpleError::new(1, e)), + }, + None => { + return Err(USimpleError::new( + 1, + get_message_with_args( + "stty-error-missing-argument", + HashMap::from([("arg".to_string(), arg.to_string())]), + ), + )); + } + } + } else if *arg == "time" { + match args_iter.next() { + Some(time) => match parse_u8_or_err(time) { + Ok(n) => valid_args + .push(ArgOptions::Mapping((SpecialCharacterIndices::VTIME, n))), + Err(e) => return Err(USimpleError::new(1, e)), + }, + None => { + return Err(USimpleError::new( + 1, + get_message_with_args( + "stty-error-missing-argument", + HashMap::from([("arg".to_string(), arg.to_string())]), + ), + )); + } + } + // baud rate setting } else if let Some(baud_flag) = string_to_baud(arg) { valid_args.push(ArgOptions::Flags(baud_flag)); // non control char flag diff --git a/tests/by-util/test_stty.rs b/tests/by-util/test_stty.rs index 9a2d5a64c..b6f569fa5 100644 --- a/tests/by-util/test_stty.rs +++ b/tests/by-util/test_stty.rs @@ -260,3 +260,36 @@ fn line() { .fails() .stderr_contains("invalid integer argument: '256'"); } + +#[test] +fn min_and_time() { + new_ucmd!() + .args(&["min"]) + .fails() + .stderr_contains("missing argument to 'min'"); + + new_ucmd!() + .args(&["time"]) + .fails() + .stderr_contains("missing argument to 'time'"); + + new_ucmd!() + .args(&["min", "-1"]) + .fails() + .stderr_contains("invalid integer argument: '-1'"); + + new_ucmd!() + .args(&["time", "-1"]) + .fails() + .stderr_contains("invalid integer argument: '-1'"); + + new_ucmd!() + .args(&["min", "256"]) + .fails() + .stderr_contains("invalid integer argument: '256': Value too large for defined data type"); + + new_ucmd!() + .args(&["time", "256"]) + .fails() + .stderr_contains("invalid integer argument: '256': Value too large for defined data type"); +}