Macros to add duration value parsers for clap arguments, where the fields are compile-time checked
1. duration_range_value_parse
To be used as the value_parse value on a clap arg
2. assign_duration_range_validator
Create a constant to be used on multiple arguments of a clap arg
3. duration_range_validator
Create a DurationHumanValidator with compile-time checking
```rust use clap::Parser; use clapduration::durationrangevalueparse; use duration_human::{DurationHuman, DurationHumanValidator};
struct SampleOptions { #[arg( long, defaultvalue="666000ms", valueparser = durationrangevalue_parse!(min: 10min, max: 1h) )] interval: DurationHuman, }
let opts = SampleOptions::parse(); asserteq!(format!("{:#}",opts.interval), format!("11min 6s")); asserteq!(opts.interval.tostring(), "666s".tostring()) ```
```rust use clap::Parser; use clapduration::durationrangevalueparse; use duration_human::{DurationHuman, DurationHumanValidator};
assigndurationrangevalidator!( LIFETIMERANGE = {default: 2h, min: 333s, max: 60day});
struct ServerOptions {
#[arg(
long,
help = format!("What lifetime will it have, between {}", LIFETIME_RANGE),
default_value = LIFETIME_RANGE.default,
value_parser = {|lifetime: &str|LIFETIME_RANGE.parse_and_validate(lifetime)}
)]
lifetime: DurationHuman,
}
let opts = ServerOptions::parse(); asserteq!(format!("{:#}",opts.lifetime), format!("11min 6s")); asserteq!(opts.lifetime.tostring(), "666s".tostring());
```