File: change.rs

package info (click to toggle)
rust-clap-num 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: makefile: 2
file content (17 lines) | stat: -rw-r--r-- 317 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use clap::Parser;
use clap_num::number_range;

fn less_than_100(s: &str) -> Result<u8, String> {
    number_range(s, 0, 99)
}

#[derive(Parser)]
struct Change {
    #[clap(long, value_parser=less_than_100)]
    cents: u8,
}

fn main() {
    let args = Change::parse();
    println!("Change: {} cents", args.cents);
}