Skip to content

Commit 394ee97

Browse files
authored
Merge pull request #435 from Taxrosdev/main
watch: fix minimum seconds
2 parents cb2c9d3 + 403830d commit 394ee97

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ feat_common_core = [
5353
[workspace.dependencies]
5454
bytesize = "2.0.0"
5555
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
56-
clap = { version = "4.5.4", features = ["wrap_help", "cargo"] }
56+
clap = { version = "4.5.4", features = ["wrap_help", "cargo", "env"] }
5757
clap_complete = "4.5.2"
5858
clap_mangen = "0.2.20"
5959
crossterm = "0.29.0"

src/uu/watch/src/watch.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ fn parse_interval(input: &str) -> Result<Duration, ParseIntError> {
1919
// Find index where to split string into seconds and nanos
2020
let Some(index) = input.find([',', '.']) else {
2121
let seconds: u64 = input.parse()?;
22-
return Ok(Duration::new(seconds, 0));
22+
23+
return if seconds == 0 {
24+
Ok(Duration::from_millis(100))
25+
} else {
26+
Ok(Duration::new(seconds, 0))
27+
};
2328
};
2429

2530
// If the seconds string is empty, set seconds to 0
@@ -250,4 +255,16 @@ mod parse_interval_tests {
250255
let interval = parse_interval("1.00000000000a");
251256
assert!(interval.is_err())
252257
}
258+
259+
#[test]
260+
fn test_minimum_seconds() {
261+
let interval = parse_interval("0");
262+
assert_eq!(Ok(Duration::from_millis(100)), interval);
263+
}
264+
265+
#[test]
266+
fn test_minimum_nanos() {
267+
let interval = parse_interval("0.0");
268+
assert_eq!(Ok(Duration::from_millis(100)), interval);
269+
}
253270
}

0 commit comments

Comments
 (0)