Add --regex option to override --glob

This commit is contained in:
sharkdp 2019-09-15 15:48:34 +02:00 committed by David Peter
parent d5da615c17
commit eac20a8132
2 changed files with 18 additions and 1 deletions

View File

@ -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). \

View File

@ -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() {