diff --git a/examples/tutorial_builder/03_05_default_values.md b/examples/tutorial_builder/03_05_default_values.md index 9954f3ad..96880f16 100644 --- a/examples/tutorial_builder/03_05_default_values.md +++ b/examples/tutorial_builder/03_05_default_values.md @@ -2,19 +2,19 @@ $ 03_05_default_values --help A simple to use, efficient, and full-featured Command Line Argument Parser -Usage: 03_05_default_values[EXE] [NAME] +Usage: 03_05_default_values[EXE] [PORT] Arguments: - [NAME] [default: alice] + [PORT] [default: 2020] Options: -h, --help Print help information -V, --version Print version information $ 03_05_default_values -name: "alice" +port: 2020 -$ 03_05_default_values bob -name: "bob" +$ 03_05_default_values 22 +port: 22 ``` diff --git a/examples/tutorial_builder/03_05_default_values.rs b/examples/tutorial_builder/03_05_default_values.rs index b11042c3..d259ee06 100644 --- a/examples/tutorial_builder/03_05_default_values.rs +++ b/examples/tutorial_builder/03_05_default_values.rs @@ -1,14 +1,18 @@ -use clap::{arg, command}; +use clap::{arg, command, value_parser}; fn main() { let matches = command!() // requires `cargo` feature - .arg(arg!([NAME]).default_value("alice")) + .arg( + arg!([PORT]) + .value_parser(value_parser!(u16)) + .default_value("2020"), + ) .get_matches(); println!( - "name: {:?}", + "port: {:?}", matches - .get_one::("NAME") + .get_one::("PORT") .expect("default ensures there is always a value") ); } diff --git a/examples/tutorial_derive/03_05_default_values.md b/examples/tutorial_derive/03_05_default_values.md index 9c124b67..194f54fb 100644 --- a/examples/tutorial_derive/03_05_default_values.md +++ b/examples/tutorial_derive/03_05_default_values.md @@ -2,19 +2,19 @@ $ 03_05_default_values_derive --help A simple to use, efficient, and full-featured Command Line Argument Parser -Usage: 03_05_default_values_derive[EXE] [NAME] +Usage: 03_05_default_values_derive[EXE] [PORT] Arguments: - [NAME] [default: alice] + [PORT] [default: 2020] Options: -h, --help Print help information -V, --version Print version information $ 03_05_default_values_derive -name: "alice" +port: 2020 -$ 03_05_default_values_derive bob -name: "bob" +$ 03_05_default_values_derive 22 +port: 22 ``` diff --git a/examples/tutorial_derive/03_05_default_values.rs b/examples/tutorial_derive/03_05_default_values.rs index c49a4218..bc33a931 100644 --- a/examples/tutorial_derive/03_05_default_values.rs +++ b/examples/tutorial_derive/03_05_default_values.rs @@ -3,12 +3,12 @@ use clap::Parser; #[derive(Parser)] #[command(author, version, about, long_about = None)] struct Cli { - #[arg(default_value_t = String::from("alice"))] - name: String, + #[arg(default_value_t = 2020)] + port: u16, } fn main() { let cli = Cli::parse(); - println!("name: {:?}", cli.name); + println!("port: {:?}", cli.port); }