Skip to content

Commit

Permalink
Merge pull request #5456 from zippy-dice/fix-doc
Browse files Browse the repository at this point in the history
docs(examples): Add examples of same names multiple options.
  • Loading branch information
epage committed Apr 15, 2024
2 parents 7cbdb07 + 62a5af6 commit 0cd10d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
18 changes: 6 additions & 12 deletions examples/tutorial_builder/03_02_option_mult.md
Expand Up @@ -10,21 +10,15 @@ Options:
-V, --version Print version

$ 03_02_option_mult
name: None
names: []

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

$ 03_02_option_mult --name=bob
name: Some("bob")
$ 03_02_option_mult --name bob --name john
names: ["bob", "john"]

$ 03_02_option_mult -n bob
name: Some("bob")

$ 03_02_option_mult -n=bob
name: Some("bob")

$ 03_02_option_mult -nbob
name: Some("bob")
$ 03_02_option_mult_derive --name bob --name=john -n tom -n=chris -nsteve
name: ["bob", "john", "tom", "chris", "steve"]

```
8 changes: 7 additions & 1 deletion examples/tutorial_builder/03_02_option_mult.rs
Expand Up @@ -10,5 +10,11 @@ fn main() {
)
.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);
}
14 changes: 4 additions & 10 deletions examples/tutorial_derive/03_02_option_mult.md
Expand Up @@ -15,16 +15,10 @@ name: []
$ 03_02_option_mult_derive --name bob
name: ["bob"]

$ 03_02_option_mult_derive --name=bob
name: ["bob"]

$ 03_02_option_mult_derive -n bob
name: ["bob"]
$ 03_02_option_mult_derive --name bob --name john
name: ["bob", "john"]

$ 03_02_option_mult_derive -n=bob
name: ["bob"]

$ 03_02_option_mult_derive -nbob
name: ["bob"]
$ 03_02_option_mult_derive --name bob --name=john -n tom -n=chris -nsteve
name: ["bob", "john", "tom", "chris", "steve"]

```

0 comments on commit 0cd10d1

Please sign in to comment.