mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-19 22:23:49 -07:00
ux: suggest --fixed-strings flag
If a regex syntax error occurs, then ripgrep will suggest using the --fixed-strings flag. Fixes #727
This commit is contained in:
committed by
Andrew Gallant
parent
b6177f0459
commit
14779ed0ea
13
src/args.rs
13
src/args.rs
@@ -11,7 +11,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use clap;
|
||||
use encoding_rs::Encoding;
|
||||
use env_logger;
|
||||
use grep::{Grep, GrepBuilder};
|
||||
use grep::{Grep, GrepBuilder, Error as GrepError};
|
||||
use log;
|
||||
use num_cpus;
|
||||
use regex;
|
||||
@@ -783,7 +783,16 @@ impl<'a> ArgMatches<'a> {
|
||||
if let Some(limit) = self.regex_size_limit()? {
|
||||
gb = gb.size_limit(limit);
|
||||
}
|
||||
gb.build().map_err(From::from)
|
||||
gb.build().map_err(|err| {
|
||||
match err {
|
||||
GrepError::Regex(err) => {
|
||||
let s = format!("{}\n(Hint: Try the --fixed-strings flag \
|
||||
to search for a literal string.)", err.to_string());
|
||||
From::from(s)
|
||||
},
|
||||
err => From::from(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Builds the set of glob overrides from the command line flags.
|
||||
|
Reference in New Issue
Block a user