Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Provide a better example for positional arg append #4390

Merged
merged 2 commits into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"]
epage marked this conversation as resolved.
Show resolved Hide resolved

```
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);
}