2022-03-03 18:32:29 +00:00
|
|
|
// Note: this requires the `cargo` feature
|
|
|
|
|
2022-05-23 15:50:11 +00:00
|
|
|
use clap::{arg, command, value_parser};
|
2021-12-23 14:41:52 +00:00
|
|
|
|
|
|
|
fn main() {
|
2022-02-14 21:47:20 +00:00
|
|
|
let matches = cmd().get_matches();
|
2021-12-23 14:41:52 +00:00
|
|
|
|
|
|
|
// 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")
|
2021-12-23 14:41:52 +00:00
|
|
|
.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(
|
2021-12-23 14:41:52 +00:00
|
|
|
arg!(<PORT>)
|
|
|
|
.help("Network port to use")
|
2022-05-23 15:50:11 +00:00
|
|
|
.value_parser(value_parser!(usize)),
|
2021-12-23 14:41:52 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn verify_app() {
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd().debug_assert();
|
2021-12-23 14:41:52 +00:00
|
|
|
}
|