Function clap_num::si_number_range

source ·
pub fn si_number_range<T>(s: &str, min: T, max: T) -> Result<T, String>
Expand description

Validate a signed or unsigned integer value with a metric prefix within a range.

This combines si_number and number_range, see the documentation for those functions for details.

Example

This extends the example in si_number, and only allows a range of resistances from 1k to 999.999k.

use clap::Parser;
use clap_num::si_number_range;

fn kilo(s: &str) -> Result<u32, String> {
    si_number_range(s, 1_000, 999_999)
}

#[derive(Parser)]
struct Args {
    #[clap(short, long, value_parser=kilo)]
    resistance: u32,
}