clap-num 0.1.3

Number parsers for clap v3.
Documentation

Maintenance crates.io docs.rs Build Status

clap-num

clap V3 number parsers.

This crate contains functions to validate and parse numerical values from strings provided by clap v3.

Example

This example allow values for --frequency between 800 Hz and 3.333 MHz, with SI symbols.

use clap::Clap;
use clap_num::si_number_range;

fn frequency(s: &str) -> Result<u32, String> {
    si_number_range(s, 800, 3_333_000)
}

#[derive(Clap, Debug)]
struct Args {
    #[clap(short, long, parse(try_from_str=frequency))]
    frequency: Option<u32>,
}

let args = Args::parse();
println!("{:?}", args);