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-08-15 19:29:46 +00:00
|
|
|
fn cmd() -> clap::Command {
|
2022-07-19 18:29:31 +00:00
|
|
|
command!() // requires `cargo` feature
|
|
|
|
.arg(
|
|
|
|
arg!(<PORT>)
|
|
|
|
.help("Network port to use")
|
|
|
|
.value_parser(value_parser!(usize)),
|
|
|
|
)
|
2021-12-23 14:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-07-19 18:29:31 +00:00
|
|
|
fn verify_cmd() {
|
2022-02-14 21:47:20 +00:00
|
|
|
cmd().debug_assert();
|
2021-12-23 14:41:52 +00:00
|
|
|
}
|