mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
Bug fixes with multiple options
This commit is contained in:
parent
46bcf02a2f
commit
aed37da635
3 changed files with 30 additions and 25 deletions
|
@ -1,3 +1,5 @@
|
|||
# v0.4.13
|
||||
* Bug fixes with how multiple options are parsed
|
||||
# v0.4.12
|
||||
* Minor bug fixes
|
||||
# v0.4.11
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
|
||||
name = "clap"
|
||||
version = "0.4.12"
|
||||
version = "0.4.13"
|
||||
authors = ["Kevin K. <kbknapp@gmail.com>"]
|
||||
exclude = ["docs/*", "examples/*", "tests/*"]
|
||||
description = "A Command Line Argument Parser written in Rust"
|
||||
|
|
51
src/app.rs
51
src/app.rs
|
@ -652,23 +652,24 @@ impl App {
|
|||
true, true);
|
||||
}
|
||||
|
||||
if matches.opts.contains_key(v.name) && !v.multiple {
|
||||
self.report_error(format!("Argument --{} was supplied more than once, but does not support multiple values", arg), true, true);
|
||||
}
|
||||
|
||||
// Ensure this isn't an option being added multiple times if it doesn't suppor it
|
||||
if v.multiple && arg_val.is_some() {
|
||||
if let Some(ref mut o) = matches.opts.get_mut(v.name) {
|
||||
o.occurrences += 1;
|
||||
o.values.push(arg_val.clone().unwrap());
|
||||
return None;
|
||||
if matches.opts.contains_key(v.name) {
|
||||
if !v.multiple {
|
||||
self.report_error(format!("Argument --{} was supplied more than once, but does not support multiple values", arg), true, true);
|
||||
}
|
||||
if arg_val.is_some() {
|
||||
if let Some(ref mut o) = matches.opts.get_mut(v.name) {
|
||||
o.occurrences += 1;
|
||||
o.values.push(arg_val.clone().unwrap());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
matches.opts.insert(v.name, OptArg{
|
||||
name: v.name,
|
||||
occurrences: 1,
|
||||
values: if arg_val.is_some() { vec![arg_val.clone().unwrap()]} else {vec![]}
|
||||
});
|
||||
}
|
||||
matches.opts.insert(v.name, OptArg{
|
||||
name: v.name,
|
||||
occurrences: 1,
|
||||
values: if arg_val.is_some() { vec![arg_val.clone().unwrap()]} else {vec![]}
|
||||
});
|
||||
|
||||
if let Some(ref bl) = v.blacklist {
|
||||
for name in bl {
|
||||
self.blacklist.insert(name);
|
||||
|
@ -756,7 +757,7 @@ impl App {
|
|||
for c in arg.chars() {
|
||||
self.check_for_help_and_version(c);
|
||||
if !self.parse_single_short_flag(matches, c) {
|
||||
self.report_error(format!("Argument -{} isn't valid",c), true, true);
|
||||
self.report_error(format!("Argument -{} isn't valid",arg), true, true);
|
||||
}
|
||||
}
|
||||
return None;
|
||||
|
@ -779,15 +780,17 @@ impl App {
|
|||
true, true);
|
||||
}
|
||||
|
||||
if matches.opts.contains_key(v.name) && !v.multiple {
|
||||
self.report_error(format!("Argument -{} was supplied more than once, but does not support multiple values", arg), true, true);
|
||||
if matches.opts.contains_key(v.name) {
|
||||
if !v.multiple {
|
||||
self.report_error(format!("Argument -{} was supplied more than once, but does not support multiple values", arg), true, true);
|
||||
}
|
||||
} else {
|
||||
matches.opts.insert(v.name, OptArg{
|
||||
name: v.name,
|
||||
occurrences: 1,
|
||||
values: vec![]
|
||||
});
|
||||
}
|
||||
|
||||
matches.opts.insert(v.name, OptArg{
|
||||
name: v.name,
|
||||
occurrences: 1,
|
||||
values: vec![]
|
||||
});
|
||||
if let Some(ref bl) = v.blacklist {
|
||||
for name in bl {
|
||||
self.blacklist.insert(name);
|
||||
|
|
Loading…
Reference in a new issue