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