]>
Commit | Line | Data |
---|---|---|
923072b8 FG |
1 | // Note: this requires the `cargo` feature |
2 | ||
3 | use clap::{arg, command, value_parser}; | |
04454e1e FG |
4 | |
5 | fn main() { | |
6 | let matches = command!() | |
7 | .arg( | |
8 | arg!(<PORT>) | |
9 | .help("Network port to use") | |
923072b8 | 10 | .value_parser(value_parser!(u16).range(1..)), |
04454e1e FG |
11 | ) |
12 | .get_matches(); | |
13 | ||
14 | // Note, it's safe to call unwrap() because the arg is required | |
923072b8 FG |
15 | let port: u16 = *matches |
16 | .get_one::<u16>("PORT") | |
04454e1e FG |
17 | .expect("'PORT' is required and parsing will fail if its missing"); |
18 | println!("PORT = {}", port); | |
19 | } |