summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-02-05 19:22:44 -0500
committerAndrew Gallant <jamslam@gmail.com>2018-02-06 12:07:59 -0500
commit8cb5833ef9fd6c4c351d10a3e950339fa89adf49 (patch)
tree28310d7b592cc453371f06ead06a1d657f241038
parent85cd3f0a6e72a1d75c37be7b8ee4677a6bcc3f3d (diff)
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.
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml6
-rw-r--r--src/app.rs9
-rw-r--r--src/args.rs4
-rw-r--r--tests/tests.rs43
5 files changed, 57 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d50280fd..3acd8c31 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -41,13 +41,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clap"
-version = "2.29.2"
+version = "2.29.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -218,7 +218,7 @@ version = "0.7.1"
dependencies = [
"atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"bytecount 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "clap 2.29.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "clap 2.29.4 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding_rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"globset 0.2.1",
"grep 0.1.7",
@@ -250,7 +250,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "strsim"
-version = "0.6.0"
+version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -360,7 +360,7 @@ dependencies = [
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum bytecount 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "882585cd7ec84e902472df34a5e01891202db3bf62614e1f0afe459c1afcf744"
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
-"checksum clap 2.29.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4151c5790817c7d21bbdc6c3530811f798172915f93258244948b93ba19604a6"
+"checksum clap 2.29.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7b8f59bcebcfe4269b09f71dab0da15b355c75916a8f975d3876ce81561893ee"
"checksum crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "24ce9782d4d5c53674646a6a4c1863a21a8fc0cb649b3c94dfc16e45071dea19"
"checksum encoding_rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5215aabf22b83153be3ee44dfe3f940214541b2ce13d419c55e7a115c8c51a9"
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
@@ -380,7 +380,7 @@ dependencies = [
"checksum regex-syntax 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8e931c58b93d86f080c734bfd2bce7dd0079ae2331235818133c8be7f422e20e"
"checksum same-file 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3257af0472da4b8b8902102a57bafffd9991f0f43772a8af6153d597e6e4ae2"
"checksum simd 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3dd0805c7363ab51a829a1511ad24b6ed0349feaa756c4bc2f977f9f496e6673"
-"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694"
+"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693"
diff --git a/Cargo.toml b/Cargo.toml
index b36bac88..c7c9dfa3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -30,7 +30,7 @@ name = "integration"
path = "tests/tests.rs"
[workspace]
-members = [ "grep", "globset", "ignore", "termcolor", "wincolor" ]
+members = ["grep", "globset", "ignore", "termcolor", "wincolor"]
[dependencies]
atty = "0.2.2"
@@ -50,7 +50,7 @@ termcolor = { version = "0.3.3", path = "termcolor" }
globset = { version = "0.2.1", path = "globset" }
[dependencies.clap]
-version = "2.26"
+version = "2.29.4"
default-features = false
features = ["suggestions", "color"]
@@ -62,7 +62,7 @@ features = ["std", "winnt"]
lazy_static = "1"
[build-dependencies.clap]
-version = "2.26"
+version = "2.29.4"
default-features = false
features = ["suggestions", "color"]
diff --git a/src/app.rs b/src/app.rs
index ba141894..05f411ac 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -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
}
diff --git a/src/args.rs b/src/args.rs
index d0990fdc..0c25727f 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -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>> {
diff --git a/tests/tests.rs b/tests/tests.rs
index ecc840e7..e88756dc 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1166,6 +1166,49 @@ clean!(regression_493, " 're ", "input.txt", |wd: WorkDir, mut cmd: Command| {
assert_eq!(lines, " 're \n");
});
+// See: https://github.com/BurntSushi/ripgrep/issues/553
+sherlock!(regression_553_switch, "sherlock", ".",
+|wd: WorkDir, mut cmd: Command| {
+ cmd.arg("-i");
+ let lines: String = wd.stdout(&mut cmd);
+ let expected = "\
+sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock
+sherlock:be, to a very large extent, the result of luck. Sherlock Holmes
+";
+ assert_eq!(lines, expected);
+
+ // This repeats the `-i` flag.
+ cmd.arg("-i");
+ let lines: String = wd.stdout(&mut cmd);
+ let expected = "\
+sherlock:For the Doctor Watsons of this world, as opposed to the Sherlock
+sherlock:be, to a very large extent, the result of luck. Sherlock Holmes
+";
+ assert_eq!(lines, expected);
+});
+
+sherlock!(regression_553_flag, "world|attached",
+|wd: WorkDir, mut cmd: Command| {
+ cmd.arg("-C").arg("1");
+ let lines: String = wd.stdout(&mut cmd);
+ let expected = "\
+For the Doctor Watsons of this world, as opposed to the Sherlock
+Holmeses, success in the province of detective work must always
+--
+but Doctor Watson has to have it taken out for him and dusted,
+and exhibited clearly, with a label attached.
+";
+ assert_eq!(lines, expected);
+
+ cmd.arg("-C").arg("0");
+ let lines: String = wd.stdout(&mut cmd);
+ let expected = "\
+For the Doctor Watsons of this world, as opposed to the Sherlock
+and exhibited clearly, with a label attached.
+";
+ assert_eq!(lines, expected);
+});
+
// See: https://github.com/BurntSushi/ripgrep/issues/599
clean!(regression_599, "^$", "input.txt", |wd: WorkDir, mut cmd: Command| {
wd.create("input.txt", "\n\ntest\n");