mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
Merge pull request #5456 from zippy-dice/fix-doc
docs(examples): Add examples of same names multiple options.
This commit is contained in:
commit
0cd10d19f0
3 changed files with 17 additions and 23 deletions
|
@ -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"]
|
||||
|
||||
```
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 --name bob --name john
|
||||
name: ["bob", "john"]
|
||||
|
||||
$ 03_02_option_mult_derive -n bob
|
||||
name: ["bob"]
|
||||
|
||||
$ 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"]
|
||||
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue