Skip to content

Commit

Permalink
Merge pull request #4390 from sergejp/master
Browse files Browse the repository at this point in the history
docs: Provide a better example for positional arg append
  • Loading branch information
epage committed Oct 14, 2022
2 parents bd5a6ea + 3250bce commit a40c7b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions examples/tutorial_builder/03_03_positional_mult.md
Expand Up @@ -12,9 +12,12 @@ Options:
-V, --version Print version information

$ 03_03_positional_mult
name: None
names: []

$ 03_03_positional_mult bob
name: Some("bob")
names: ["bob"]

$ 03_03_positional_mult bob john
names: ["bob", "john"]

```
8 changes: 7 additions & 1 deletion examples/tutorial_builder/03_03_positional_mult.rs
Expand Up @@ -5,5 +5,11 @@ fn main() {
.arg(Arg::new("name").action(ArgAction::Append))
.get_matches();

println!("name: {:?}", matches.get_one::<String>("name"));
let args = matches
.get_many::<String>("name")
.unwrap_or_default()
.map(|v| v.as_str())
.collect::<Vec<_>>();

println!("names: {:?}", &args);
}
3 changes: 3 additions & 0 deletions examples/tutorial_derive/03_03_positional_mult.md
Expand Up @@ -17,4 +17,7 @@ name: []
$ 03_03_positional_mult_derive bob
name: ["bob"]

$ 03_03_positional_mult_derive bob john
name: ["bob", "john"]

```

0 comments on commit a40c7b4

Please sign in to comment.