| 1 |
use clap::{arg, command, value_parser}; |
| 2 |
|
| 3 |
fn main() { |
| 4 |
let matches = cmd().get_matches(); |
| 5 |
|
| 6 |
// Note, it's safe to call unwrap() because the arg is required |
| 7 |
let port: usize = *matches |
| 8 |
.get_one::<usize>("PORT") |
| 9 |
.expect("'PORT' is required and parsing will fail if its missing"); |
| 10 |
println!("PORT = {port}"); |
| 11 |
} |
| 12 |
|
| 13 |
fn cmd() -> clap::Command { |
| 14 |
command!() // requires `cargo` feature |
| 15 |
.arg( |
| 16 |
arg!(<PORT>) |
| 17 |
.help("Network port to use") |
| 18 |
.value_parser(value_parser!(usize)), |
| 19 |
) |
| 20 |
} |
| 21 |
|
| 22 |
#[test] |
| 23 |
fn verify_cmd() { |
| 24 |
cmd().debug_assert(); |
| 25 |
} |