Skip to main content

parse_cooldown

Function parse_cooldown 

Source
pub fn parse_cooldown(input: &str) -> Result<u64, String>
Expand description

Parses a --cooldown value into a clamped second count.

Accepts a bare integer (seconds) or an integer suffixed with s/m/h/d. Clamped to MAX_COOLDOWN_SECS so a CLI override can never exceed deps.toml’s own bound.

§Examples

use deps_cli::cli::parse_cooldown;

assert_eq!(parse_cooldown("3600").unwrap(), 3600);
assert_eq!(parse_cooldown("1h").unwrap(), 3600);
assert_eq!(parse_cooldown("3d").unwrap(), 3 * 24 * 60 * 60);
assert!(parse_cooldown("nonsense").is_err());

§Errors

Returns a human-readable message when input is empty, has a non-numeric magnitude, or uses an unrecognized unit suffix.