6 releases (1 stable)

Uses new Rust 2021

1.0.0 Jan 1, 2022
0.2.0 Oct 18, 2020
0.1.3 Aug 8, 2020
0.1.2 Jul 30, 2020

#99 in Command-line interface

Download history 5/week @ 2021-10-12 12/week @ 2021-10-19 5/week @ 2021-10-26 3/week @ 2021-11-02 6/week @ 2021-11-09 4/week @ 2021-11-16 192/week @ 2021-11-23 33/week @ 2021-11-30 33/week @ 2021-12-07 40/week @ 2021-12-14 136/week @ 2021-12-21 165/week @ 2021-12-28 77/week @ 2022-01-04 43/week @ 2022-01-11 23/week @ 2022-01-18

319 downloads per month
Used in ftzz

MIT license

15KB
174 lines

crates.io docs.rs Build Status

clap-num

clap number parsers.

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

Example

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

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

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

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

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

lib.rs:

clap number parsers.

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

Example

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

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

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

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

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

Dependencies

~140KB