docs(tutorial): Focus on actions, not macros

This commit is contained in:
Ed Page 2022-08-08 14:07:57 -05:00
parent 6aa4f90609
commit 78b2b44b95
7 changed files with 20 additions and 15 deletions

View file

@ -1,8 +1,13 @@
use clap::{arg, command, ArgAction};
use clap::{command, Arg, ArgAction};
fn main() {
let matches = command!() // requires `cargo` feature
.arg(arg!(-v - -verbose).action(ArgAction::Count))
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.action(ArgAction::Count),
)
.get_matches();
println!(

View file

@ -7,7 +7,7 @@ USAGE:
03_02_option[EXE] [OPTIONS]
OPTIONS:
-n, --name <NAME>
-n, --name <name>
-h, --help Print help information
-V, --version Print version information

View file

@ -1,8 +1,8 @@
use clap::{arg, command};
use clap::{command, Arg};
fn main() {
let matches = command!() // requires `cargo` feature
.arg(arg!(-n --name <NAME>).required(false))
.arg(Arg::new("name").short('n').long("name"))
.get_matches();
println!("name: {:?}", matches.get_one::<String>("name"));

View file

@ -4,19 +4,19 @@ clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser
USAGE:
03_03_positional[EXE] [NAME]
03_03_positional[EXE] [name]
ARGS:
<NAME>
<name>
OPTIONS:
-h, --help Print help information
-V, --version Print version information
$ 03_03_positional
NAME: None
name: None
$ 03_03_positional bob
NAME: Some("bob")
name: Some("bob")
```

View file

@ -1,9 +1,9 @@
use clap::{arg, command};
use clap::{command, Arg};
fn main() {
let matches = command!() // requires `cargo` feature
.arg(arg!([NAME]))
.arg(Arg::new("name"))
.get_matches();
println!("NAME: {:?}", matches.get_one::<String>("NAME"));
println!("name: {:?}", matches.get_one::<String>("name"));
}

View file

@ -14,9 +14,9 @@ OPTIONS:
-V, --version Print version information
$ 03_05_default_values
NAME: "alice"
name: "alice"
$ 03_05_default_values bob
NAME: "bob"
name: "bob"
```

View file

@ -6,7 +6,7 @@ fn main() {
.get_matches();
println!(
"NAME: {:?}",
"name: {:?}",
matches
.get_one::<String>("NAME")
.expect("default ensures there is always a value")