mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-11-29 05:57:07 +02:00
argv: update clap to 2.29.4
We use the new AppSettings::AllArgsOverrideSelf to permit all flags to be specified multiple times. This removes the need for our previous work-around where we would enable `multiple` for every flag and then just extract the last value when consuming clap's matches. We also add a couple regression tests that ensure repeated switches and flags work as expected.
This commit is contained in:
@@ -67,6 +67,7 @@ pub fn app() -> App<'static, 'static> {
|
||||
.about(ABOUT)
|
||||
.max_term_width(100)
|
||||
.setting(AppSettings::UnifiedHelpMessage)
|
||||
.setting(AppSettings::AllArgsOverrideSelf)
|
||||
.usage(USAGE)
|
||||
.template(TEMPLATE)
|
||||
.help_message("Prints help information. Use --help for more details.");
|
||||
@@ -250,8 +251,7 @@ impl RGArg {
|
||||
/// inspect the number of times the switch is used.
|
||||
fn switch(long_name: &'static str) -> RGArg {
|
||||
let claparg = Arg::with_name(long_name)
|
||||
.long(long_name)
|
||||
.multiple(true);
|
||||
.long(long_name);
|
||||
RGArg {
|
||||
claparg: claparg,
|
||||
name: long_name,
|
||||
@@ -280,7 +280,6 @@ impl RGArg {
|
||||
.long(long_name)
|
||||
.value_name(value_name)
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
.number_of_values(1);
|
||||
RGArg {
|
||||
claparg: claparg,
|
||||
@@ -351,11 +350,8 @@ impl RGArg {
|
||||
// document it distinct for each different kind. See RGArgKind docs.
|
||||
match self.kind {
|
||||
RGArgKind::Positional { ref mut multiple, .. } => {
|
||||
self.claparg = self.claparg.multiple(true);
|
||||
*multiple = true;
|
||||
}
|
||||
// We don't need to modify clap's state in the following cases
|
||||
// because all switches and flags always have `multiple` enabled.
|
||||
RGArgKind::Switch { ref mut multiple, .. } => {
|
||||
*multiple = true;
|
||||
}
|
||||
@@ -363,6 +359,7 @@ impl RGArg {
|
||||
*multiple = true;
|
||||
}
|
||||
}
|
||||
self.claparg = self.claparg.multiple(true);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -994,7 +994,7 @@ impl<'a> ArgMatches<'a> {
|
||||
}
|
||||
|
||||
fn value_of_lossy(&self, name: &str) -> Option<String> {
|
||||
self.values_of_lossy(name).and_then(|mut vals| vals.pop())
|
||||
self.0.value_of_lossy(name).map(|s| s.into_owned())
|
||||
}
|
||||
|
||||
fn values_of_lossy(&self, name: &str) -> Option<Vec<String>> {
|
||||
@@ -1002,7 +1002,7 @@ impl<'a> ArgMatches<'a> {
|
||||
}
|
||||
|
||||
fn value_of_os(&'a self, name: &str) -> Option<&'a OsStr> {
|
||||
self.values_of_os(name).and_then(|it| it.last())
|
||||
self.0.value_of_os(name)
|
||||
}
|
||||
|
||||
fn values_of_os(&'a self, name: &str) -> Option<clap::OsValues<'a>> {
|
||||
|
||||
Reference in New Issue
Block a user