]> git.proxmox.com Git - rustc.git/blob - vendor/clap/examples/tutorial_builder/04_02_parse.rs
New upstream version 1.65.0+dfsg1
[rustc.git] / vendor / clap / examples / tutorial_builder / 04_02_parse.rs
1 use clap::{arg, command, value_parser};
2
3 fn main() {
4 let matches = command!() // requires `cargo` feature
5 .arg(
6 arg!(<PORT>)
7 .help("Network port to use")
8 .value_parser(value_parser!(u16).range(1..)),
9 )
10 .get_matches();
11
12 // Note, it's safe to call unwrap() because the arg is required
13 let port: u16 = *matches
14 .get_one::<u16>("PORT")
15 .expect("'PORT' is required and parsing will fail if its missing");
16 println!("PORT = {}", port);
17 }