From eac20a813256ecdd387c28d32abee26b5da66c35 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sun, 15 Sep 2019 15:48:34 +0200 Subject: [PATCH] Add --regex option to override --glob --- src/app.rs | 11 ++++++++++- tests/tests.rs | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 2fbae23..c0b06e1 100644 --- a/src/app.rs +++ b/src/app.rs @@ -73,6 +73,12 @@ pub fn build_app() -> App<'static, 'static> { .short("g") .conflicts_with("fixed-strings"), ) + .arg( + arg("regex") + .long("regex") + .overrides_with("glob") + .hidden_short_help(true), + ) .arg( arg("fixed-strings") .long("fixed-strings") @@ -259,6 +265,9 @@ fn usage() -> HashMap<&'static str, Help> { doc!(h, "glob" , "Glob-based search (default: regular expression)" , "Perform a glob-based search instead of a regular expression search."); + doc!(h, "regex" + , "Perform a regex-based search" + , "Perform a regular-expression based seach (default). This can be used to override --glob."); doc!(h, "fixed-strings" , "Treat the pattern as a literal string" , "Treat the pattern as a literal string instead of a regular expression."); @@ -346,7 +355,7 @@ fn usage() -> HashMap<&'static str, Help> { , "Amount of time in milliseconds to buffer, before streaming the search results to \ the console."); doc!(h, "pattern" - , "the search pattern, a regular expression (optional)"); + , "the search pattern: a regular expression unless '--glob' is used (optional)"); doc!(h, "path" , "the root directory for the filesystem search (optional)" , "The directory where the filesystem search is rooted (optional). \ diff --git a/tests/tests.rs b/tests/tests.rs index 0503ccf..32dc7f4 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -313,6 +313,14 @@ fn test_glob_searches_with_extension() { ); } +/// Make sure that --regex overrides --glob +#[test] +fn test_regex_overrides_glob() { + let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES); + + te.assert_output(&["--glob", "--regex", "Foo2$"], "one/two/C.Foo2"); +} + /// Full path search (--full-path) #[test] fn test_full_path() {