diff --git a/src/cli.rs b/src/cli.rs index 5b84dbb..5746427 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use chrono::{format::Parsed, Duration}; use clap::Parser; -use color_eyre::eyre::Result; +use color_eyre::eyre::{bail, eyre, Result}; use serde_with::serde_as; use crate::utils::version; @@ -20,9 +20,9 @@ pub struct Cli { #[arg( short = 'n', long = "interval", - value_parser = parse_duration_from_str, + value_parser = validate_duration, default_value = "2s", - help = "Seconds to wait between updates", + help = "Seconds to wait between updates (>= 100ms)", )] pub interval: Duration, @@ -123,6 +123,15 @@ pub struct Cli { pub load: Option, } +fn validate_duration(s: &str) -> Result { + let d = parse_duration_from_str(s)?; + if d < Duration::milliseconds(100) { + bail!("The short interval is not allowed (less than 100ms)"); + } + + Ok(d) +} + fn parse_duration_from_str(s: &str) -> Result { match humantime::parse_duration(s) { Ok(d) => Ok(Duration::from_std(d)?),