clap/examples/tutorial_builder/04_02_parse.rs

20 lines
547 B
Rust
Raw Normal View History

// Note: this requires the `cargo` feature
2022-05-23 15:50:11 +00:00
use clap::{arg, command, value_parser};
fn main() {
2022-02-15 14:33:38 +00:00
let matches = command!()
.arg(
arg!(<PORT>)
.help("Network port to use")
2022-05-23 15:50:11 +00:00
.value_parser(value_parser!(u16).range(1..)),
)
.get_matches();
// Note, it's safe to call unwrap() because the arg is required
2022-05-23 15:50:11 +00:00
let port: u16 = *matches
.get_one::<u16>("PORT")
.expect("'PORT' is required and parsing will fail if its missing");
println!("PORT = {}", port);
}