File: 03_05_default_values.rs

package info (click to toggle)
rust-clap 4.5.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 908 kB
  • sloc: makefile: 2
file content (18 lines) | stat: -rw-r--r-- 434 bytes parent folder | download | duplicates (46)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use clap::{arg, command, value_parser};

fn main() {
    let matches = command!() // requires `cargo` feature
        .arg(
            arg!([PORT])
                .value_parser(value_parser!(u16))
                .default_value("2020"),
        )
        .get_matches();

    println!(
        "port: {:?}",
        matches
            .get_one::<u16>("PORT")
            .expect("default ensures there is always a value")
    );
}