From 6dce04963d4ee2d1bd6c17559d237f6dc88e048e Mon Sep 17 00:00:00 2001 From: dana Date: Sat, 29 Jul 2017 10:54:10 -0500 Subject: Allow options with non-numeric arguments to accept leading hyphens in arguments (fixes #568) --- src/app.rs | 8 +++++++- tests/tests.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 6ca3489c..bb1e89c4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -90,9 +90,11 @@ pub fn app() -> App<'static, 'static> { .arg(flag("fixed-strings").short("F")) .arg(flag("glob").short("g") .takes_value(true).multiple(true).number_of_values(1) + .set(ArgSettings::AllowLeadingHyphen) .value_name("GLOB")) .arg(flag("iglob") .takes_value(true).multiple(true).number_of_values(1) + .set(ArgSettings::AllowLeadingHyphen) .value_name("GLOB")) .arg(flag("ignore-case").short("i")) .arg(flag("line-number").short("n")) @@ -126,6 +128,7 @@ pub fn app() -> App<'static, 'static> { .arg(flag("debug")) .arg(flag("file").short("f") .value_name("FILE").takes_value(true) + .set(ArgSettings::AllowLeadingHyphen) .multiple(true).number_of_values(1)) .arg(flag("files-with-matches").short("l")) .arg(flag("files-without-match")) @@ -136,6 +139,7 @@ pub fn app() -> App<'static, 'static> { .arg(flag("hidden")) .arg(flag("ignore-file") .value_name("FILE").takes_value(true) + .set(ArgSettings::AllowLeadingHyphen) .multiple(true).number_of_values(1)) .arg(flag("follow").short("L")) .arg(flag("max-count") @@ -156,7 +160,9 @@ pub fn app() -> App<'static, 'static> { .arg(flag("only-matching").short("o").conflicts_with("replace")) .arg(flag("path-separator").value_name("SEPARATOR").takes_value(true)) .arg(flag("pretty").short("p")) - .arg(flag("replace").short("r").value_name("ARG").takes_value(true)) + .arg(flag("replace").short("r") + .set(ArgSettings::AllowLeadingHyphen) + .value_name("ARG").takes_value(true)) .arg(flag("regex-size-limit") .value_name("NUM+SUFFIX?").takes_value(true)) .arg(flag("case-sensitive").short("s")) diff --git a/tests/tests.rs b/tests/tests.rs index 8e0c9e0b..86fab015 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1705,6 +1705,7 @@ fn regression_483_non_matching_exit_code() { wd.assert_err(&mut cmd); } + // See: https://github.com/BurntSushi/ripgrep/issues/506 #[test] fn regression_506_word_boundaries_not_parenthesized() { @@ -1720,7 +1721,19 @@ fn regression_506_word_boundaries_not_parenthesized() { let expected = "min\nmax\n"; assert_eq!(lines, expected); +} + +// See: https://github.com/BurntSushi/ripgrep/issues/568 +#[test] +fn regression_568_leading_hyphen_option_arguments() { + let wd = WorkDir::new("regression_568_leading_hyphen_option_arguments"); + let path = "file"; + wd.create(path, "foo bar baz\n"); + let mut cmd = wd.command(); + cmd.arg("-r").arg("-n").arg("-i").arg("bar").arg(path); + let lines: String = wd.stdout(&mut cmd); + assert_eq!(lines, "foo -n baz\n"); } #[test] -- cgit v1.2.3