2022-05-23 15:50:11 +00:00
|
|
|
use clap::{arg, command, value_parser};
|
2022-02-08 04:50:39 +00:00
|
|
|
|
|
|
|
fn main() {
|
2022-07-19 18:29:31 +00:00
|
|
|
let matches = command!() // requires `cargo` feature
|
2022-02-08 04:50:39 +00:00
|
|
|
.arg(
|
|
|
|
arg!(<PORT>)
|
|
|
|
.help("Network port to use")
|
2022-05-23 15:50:11 +00:00
|
|
|
.value_parser(value_parser!(u16).range(1..)),
|
2022-02-08 04:50:39 +00:00
|
|
|
)
|
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
// Note, it's safe to call unwrap() because the arg is required
|
2022-05-23 15:50:11 +00:00
|
|
|
let port: u16 = *matches
|
|
|
|
.get_one::<u16>("PORT")
|
2022-02-08 04:50:39 +00:00
|
|
|
.expect("'PORT' is required and parsing will fail if its missing");
|
2023-05-04 19:53:36 +00:00
|
|
|
println!("PORT = {port}");
|
2022-02-08 04:50:39 +00:00
|
|
|
}
|