mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-05-19 01:30:21 -07:00
ripgrep: suggest -U/--multiline
When a "\n literal is not allowed" error is reported, ripgrep will now suggest the use of the -U/--multiline flag, which enables matching newlines. Fixes #1055
This commit is contained in:
parent
ba533f390e
commit
db256c87eb
16
src/args.rs
16
src/args.rs
@ -615,7 +615,10 @@ impl ArgMatches {
|
||||
if let Some(limit) = self.dfa_size_limit()? {
|
||||
builder.dfa_size_limit(limit);
|
||||
}
|
||||
Ok(builder.build(&patterns.join("|"))?)
|
||||
match builder.build(&patterns.join("|")) {
|
||||
Ok(m) => Ok(m),
|
||||
Err(err) => Err(From::from(suggest_multiline(err.to_string()))),
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a matcher using PCRE2.
|
||||
@ -1546,6 +1549,17 @@ and look-around.", msg)
|
||||
}
|
||||
}
|
||||
|
||||
fn suggest_multiline(msg: String) -> String {
|
||||
if msg.contains("the literal") && msg.contains("not allowed") {
|
||||
format!("{}
|
||||
|
||||
Consider enabling multiline mode with the --multiline flag (or -U for short).
|
||||
When multiline mode is enabled, new line characters can be matched.", msg)
|
||||
} else {
|
||||
msg
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert the result of parsing a human readable file size to a `usize`,
|
||||
/// failing if the type does not fit.
|
||||
fn u64_to_usize(
|
||||
|
Loading…
x
Reference in New Issue
Block a user