mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 23:02:31 +00:00
85f541d789
Impact: - Binary size: 556.6 KiB to 578.4 KiB - build time: 6.4950 us (7% slower) - parse time: 7.7256 us - parse sc time: 8.1580 us (5% faster) Fixes #1041 Fixes #2150
25 lines
613 B
Rust
25 lines
613 B
Rust
use clap::{arg, command, value_parser};
|
|
|
|
fn main() {
|
|
let matches = cmd().get_matches();
|
|
|
|
// Note, it's safe to call unwrap() because the arg is required
|
|
let port: usize = *matches
|
|
.get_one::<usize>("PORT")
|
|
.expect("'PORT' is required and parsing will fail if its missing");
|
|
println!("PORT = {}", port);
|
|
}
|
|
|
|
fn cmd() -> clap::Command {
|
|
command!() // requires `cargo` feature
|
|
.arg(
|
|
arg!(<PORT>)
|
|
.help("Network port to use")
|
|
.value_parser(value_parser!(usize)),
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn verify_cmd() {
|
|
cmd().debug_assert();
|
|
}
|