clap/examples/tutorial_builder/05_01_assert.rs

27 lines
613 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-14 21:47:20 +00:00
let matches = cmd().get_matches();
// Note, it's safe to call unwrap() because the arg is required
2022-05-23 15:50:11 +00:00
let port: usize = *matches
.get_one::<usize>("PORT")
.expect("'PORT' is required and parsing will fail if its missing");
println!("PORT = {}", port);
}
2022-02-14 21:47:20 +00:00
fn cmd() -> clap::Command<'static> {
2022-02-15 14:33:38 +00:00
command!().arg(
arg!(<PORT>)
.help("Network port to use")
2022-05-23 15:50:11 +00:00
.value_parser(value_parser!(usize)),
)
}
#[test]
fn verify_app() {
2022-02-14 21:47:20 +00:00
cmd().debug_assert();
}