Add dfa-size-limit and regex-size-limit arguments

Fixes #362.
This commit is contained in:
Marc Tiehuis
2017-04-02 09:55:58 +12:00
committed by Andrew Gallant
parent 1f2a9b0306
commit 66efbad871
3 changed files with 139 additions and 23 deletions

View File

@@ -41,7 +41,9 @@ OPTIONS:
/// in a `build.rs` script to build shell completion files.
pub fn app() -> App<'static, 'static> {
let arg = |name| {
Arg::with_name(name).help(USAGES[name].short).long_help(USAGES[name].long)
Arg::with_name(name)
.help(USAGES[name].short)
.long_help(USAGES[name].long)
};
let flag = |name| arg(name).long(name);
@@ -53,7 +55,7 @@ pub fn app() -> App<'static, 'static> {
.setting(AppSettings::UnifiedHelpMessage)
.usage(USAGE)
.template(TEMPLATE)
.help_message("Prints help information. Use --help for more details.")
.help_message("Prints help information. Use --help for more details.")
// First, set up primary positional/flag arguments.
.arg(arg("pattern")
.required_unless_one(&[
@@ -114,6 +116,8 @@ pub fn app() -> App<'static, 'static> {
.arg(flag("column"))
.arg(flag("context-separator")
.value_name("SEPARATOR").takes_value(true))
.arg(flag("dfa-size-limit")
.value_name("NUM+SUFFIX?").takes_value(true))
.arg(flag("debug"))
.arg(flag("file").short("f")
.value_name("FILE").takes_value(true)
@@ -148,6 +152,8 @@ pub fn app() -> App<'static, 'static> {
.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("regex-size-limit")
.value_name("NUM+SUFFIX?").takes_value(true))
.arg(flag("case-sensitive").short("s"))
.arg(flag("smart-case").short("S"))
.arg(flag("sort-files"))
@@ -326,6 +332,13 @@ lazy_static! {
doc!(h, "debug",
"Show debug messages.",
"Show debug messages. Please use this when filing a bug report.");
doc!(h, "dfa-size-limit",
"The upper size limit of the generated dfa.",
"The upper size limit of the generated dfa. The default limit is \
10M. This should only be changed on very large regex inputs \
where the (slower) fallback regex engine may otherwise be used. \
\n\nThe argument accepts the same size suffixes as allowed in \
the 'max-filesize' argument.");
doc!(h, "file",
"Search for patterns from the given file.",
"Search for patterns from the given file, with one pattern per \
@@ -444,6 +457,11 @@ lazy_static! {
Note that the replacement by default replaces each match, and \
NOT the entire line. To replace the entire line, you should \
match the entire line.");
doc!(h, "regex-size-limit",
"The upper size limit of the compiled regex.",
"The upper size limit of the compiled regex. The default limit \
is 10M. \n\nThe argument accepts the same size suffixes as \
allowed in the 'max-filesize' argument.");
doc!(h, "case-sensitive",
"Search case sensitively.",
"Search case sensitively. This overrides -i/--ignore-case and \