3 releases

new 0.1.2 Jul 30, 2020
0.1.1 Jul 30, 2020
0.1.0 Jul 30, 2020

#178 in Command-line interface

MIT license

13KB
150 lines

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);

lib.rs:

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);

Dependencies

~140KB