summaryrefslogtreecommitdiffstats
path: root/src/args.rs
AgeCommit message (Collapse)Author
2019-05-29progressag/snafuAndrew Gallant
2019-04-15ripgrep: max-column-preview --> max-columns-previewAndrew Gallant
Credit to @okdana for catching this. This naming is a bit more consistent with the existing --max-columns flag.
2019-04-14ripgrep: add --auto-hybrid-regex flagAndrew Gallant
This flag, when set, will automatically dispatch to PCRE2 if the given regex cannot be compiled by Rust's regex engine. If both engines fail to compile the regex, then both errors are surfaced. Closes #1155
2019-04-14ripgrep: increase pcre2's default JIT stack sizeAndrew Gallant
The default stack size is 32KB, and this increases it to 10MB. 32KB is pretty paltry in the environments in which ripgrep runs, and 10MB is easily afforded as a maximum size. (The size limit we set for Rust's regex engine is considerably larger.) This was motivated due to the fack that JIT stack limits have been observed to be hit in the wild: https://github.com/Microsoft/vscode/issues/64606
2019-04-14ripgrep: add --pcre2-version flagAndrew Gallant
This flag will output details about the version of PCRE2 that ripgrep is using (if any).
2019-04-14printer: support previews for long linesAndrew Gallant
This commit adds support for showing a preview of long lines. While the default still remains as completely suppressing the entire line, this new functionality will show the first N graphemes of a matching line, including the number of matches that are suppressed. This was unfortunately a fairly invasive change to the printer that required a bit of refactoring. On the bright side, the single line and multi-line coloring are now more unified than they were before. Closes #1078
2019-04-14binary: rejigger ripgrep's handling of binary filesAndrew Gallant
This commit attempts to surface binary filtering in a slightly more user friendly way. Namely, before, ripgrep would silently stop searching a file if it detected a NUL byte, even if it had previously printed a match. This can lead to the user quite reasonably assuming that there are no more matches, since a partial search is fairly unintuitive. (ripgrep has this behavior by default because it really wants to NOT search binary files at all, just like it doesn't search gitignored or hidden files.) With this commit, if a match has already been printed and ripgrep detects a NUL byte, then it will print a warning message indicating that the search stopped prematurely. Moreover, this commit adds a new flag, --binary, which causes ripgrep to stop filtering binary files, but in a way that still avoids dumping binary data into terminals. That is, the --binary flag makes ripgrep behave more like grep's default behavior. For files explicitly specified in a search, e.g., `rg foo some-file`, then no binary filtering is applied (just like no gitignore and no hidden file filtering is applied). Instead, ripgrep behaves as if you gave the --binary flag for all explicitly given files. This was a fairly invasive change, and potentially increases the UX complexity of ripgrep around binary files. (Before, there were two binary modes, where as now there are three.) However, ripgrep is now a bit louder with warning messages when binary file detection might otherwise be hiding potential matches, so hopefully this is a net improvement. Finally, the `-uuu` convenience now maps to `--no-ignore --hidden --binary`, since this is closer to the actualy intent of the `--unrestricted` flag, i.e., to reduce ripgrep's smart filtering. As a consequence, `rg -uuu foo` should now search roughly the same number of bytes as `grep -r foo`, and `rg -uuua foo` should search roughly the same number of bytes as `grep -ra foo`. (The "roughly" weasel word is used because grep's and ripgrep's binary file detection might differ somewhat---perhaps based on buffer sizes---which can impact exactly what is and isn't searched.) See the numerous tests in tests/binary.rs for intended behavior. Fixes #306, Fixes #855
2019-04-07regex: make multi-literal searcher fasterAndrew Gallant
This makes the case of searching for a dictionary of a very large number of literals much much faster. (~10x or so.) In particular, we achieve this by short-circuiting the construction of a full regex when we know we have a simple alternation of literals. Building the regex for a large dictionary (>100,000 literals) turns out to be quite slow, even if it internally will dispatch to Aho-Corasick. Even that isn't quite enough. It turns out that even *parsing* such a regex is quite slow. So when the -F/--fixed-strings flag is set, we short circuit regex parsing completely and jump straight to Aho-Corasick. We aren't quite as fast as GNU grep here, but it's much closer (less than 2x slower). In general, this is somewhat of a hack. In particular, it seems plausible that this optimization could be implemented entirely in the regex engine. Unfortunately, the regex engine's internals are just not amenable to this at all, so it would require a larger refactoring effort. For now, it's good enough to add this fairly simple hack at a higher level. Unfortunately, if you don't pass -F/--fixed-strings, then ripgrep will be slower, because of the aforementioned missing optimization. Moreover, passing flags like `-i` or `-S` will cause ripgrep to abandon this optimization and fall back to something potentially much slower. Again, this fix really needs to happen inside the regex engine, although we might be able to special case -i when the input literals are pure ASCII via Aho-Corasick's `ascii_case_insensitive`. Fixes #497, Fixes #838
2019-04-06searcher: add option to disable BOM sniffinglesnyrumcajs
This commit adds a new encoding feature where the -E/--encoding flag will now accept a value of 'none'. When given this value, all encoding related machinery is disabled and ripgrep will search the raw bytes of the file, including the BOM if it's present. Closes #1207, Closes #1208
2019-04-06ripgrep: remove extra new-line after Clap outputdana
PR #1222
2019-01-26search: fix -F and -f interaction bugAndrew Gallant
This fixes what appears to be a pretty egregious regression where the `-F/--fixed-strings` flag wasn't be applied to patterns supplied via the `-f/--file` flag. The same bug existed for the `-x/--line-regexp` flag as well, which we fix here. Fixes #1176
2019-01-26exit: tweak exit status logicAndrew Gallant
This changes how ripgrep emit exit status codes. In particular, any error that occurs while searching will now cause ripgrep to emit a `2` exit code, where as it previously would emit either a `0` or a `1` code based on whether it matched or not. That is, ripgrep would only emit a `2` exit code for a catastrophic error. This tweak includes additional logic that GNU grep adheres to, which seems like good sense. Namely, if -q/--quiet is given, and an error occurs and a match occurs, then ripgrep will emit a `0` exit code. Closes #1159
2019-01-26args: prevent panicking in 'rg -h | rg'Andrew Gallant
Previously, we relied on clap to handle printing either an error message, or --help/--version output, in addition to setting the exit status code. Unfortunately, for --help/--version output, clap was panicking if the write failed, which can happen in fairly common scenarios via a broken pipe error. e.g., `rg -h | head`. We fix this by using clap's "safe" API and doing the printing ourselves. We also set the exit code to `2` when an invalid command has been given. Fixes #1125 and partially addresses #1159
2019-01-26config: add --no-ignore-dot flagAndrew Gallant
This flag causes ripgrep to ignore `.ignore` files. Closes #1138
2019-01-23ripgrep: don't skip stdout in --files modeRob Lourens
Specifically, this avoids triggering Windows antimalware when in --files mode. See also #600. Fixes #1121
2019-01-22ripgrep: add --ignore-file-case-insensitiveDavid Torosyan
The --ignore-file-case-insensitive flag causes all .gitignore/.rgignore/.ignore files to have their globs matched without regard for case. Because this introduces a potentially significant performance regression, this is always disabled by default. Users that need case insensitive matching can enable it on a case by case basis. Closes #1164, Closes #1170
2019-01-19edition: move core ripgrep to Rust 2018Andrew Gallant
2018-09-25ripgrep: suggest -U/--multilineAndrew Gallant
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
2018-09-08pcre2: use jit_if_availablegrep-pcre2-0.1.2grep-0.2.3Andrew Gallant
This will allow PCRE2 to fall back to non-JIT matching when running on platforms without JIT support. ref https://github.com/BurntSushi/rust-pcre2/issues/3
2018-09-04ripgrep: add --pre-glob flagAndrew Gallant
The --pre-glob flag is like the --glob flag, except it applies to filtering files through the preprocessor instead of for search. This makes it possible to apply the preprocessor to only a small subset of files, which can greatly reduce the process overhead of using a preprocessor when searching large directories.
2018-09-04ripgrep: add --line-buffered and --block-bufferedAndrew Gallant
These flags provide granular control over ripgrep's buffering strategy. The --line-buffered flag can be genuinely useful in certain types of shell pipelines. The --block-buffered flag has a murkier use case, but we add it for completeness.
2018-09-04grep-cli: introduce new grep-cli crateAndrew Gallant
This commit moves a lot of "utility" code from ripgrep core into grep-cli. Any one of these things might not be worth creating a new crate, but combining everything together results in a fair number of a convenience routines that make up a decent sized crate. There is potentially more we could move into the crate, but much of what remains in ripgrep core is almost entirely dealing with the number of flags we support. In the course of doing moving things to the grep-cli crate, we clean up a lot of gunk and improve failure modes in a number of cases. In particular, we've fixed a bug where other processes could deadlock if they write too much to stderr. Fixes #990
2018-08-27ripgrep: use 'ignore' for skipping stdoutAndrew Gallant
This removes ripgrep-specific code for filtering files that correspond to stdout and instead uses the 'ignore' crate's functionality for doing the same.
2018-08-26ripgrep: add --sort and --sortr flagsAndrew Gallant
These flags each accept one of five choices: none, path, modified, accessed or created. The value indicates how the results are sorted. For --sort, results are sorted in ascending order where as for --sortr, results are sorted in descending order. Closes #404
2018-08-26ignore: add 'same_file_system' optionAndrew Gallant
This commit adds a 'same_file_system' option to the walk builder. For single threaded walking, it defers to the walkdir crate, which has the same option. The bulk of this commit implements this flag for the parallel walker. We add one very feeble test for this. The parallel walker is now officially a complete mess. Closes #321
2018-08-25ripgrep: use winapi-util for stdin_is_readableAndrew Gallant
2018-08-20ripgrep: migrate to libripgrepAndrew Gallant
This commit does the work to delete the old `grep` crate and effectively rewrite most of ripgrep core to use the new libripgrep crates. The new `grep` crate is now a facade that collects the various crates that make up libripgrep. The most complex part of ripgrep core is now arguably the translation between command line parameters and the library options, which is ultimately where we want to be.
2018-07-22ripgrep: when given no patterns, don't matchAndrew Gallant
Generally speaking, ripgrep prevents the case of not having any patterns via its arg parsing. However, it is possible for users to provide a file of patterns via the `-f` flag. If that file is empty, then ripgrep has nothing to search for and therefore should not ever produce any match. One way of fixing this might be to replace the absence of patterns with a pattern that can never match, but this still requires opening and searching through every file, which is quite a waste. Instead, we detect this case explicitly and quit early. Fixes #900
2018-07-22ripgrep: add --no-ignore-global flagAndrew Gallant
This commit adds a new --no-ignore-global flag that permits disabling the use of global gitignore filtering. Global gitignores are generally found in `$HOME/.config/git/ignore`, but its location can be configured via git's `core.excludesFile` option. Closes #934
2018-07-22ripgrep: better --path-separator error messageAndrew Gallant
This commit improves the error message when --path-separator fails. Namely, it prints the separator it got and also prints a notice for Windows users for common failure modes. Fixes #957
2018-07-21ripgrep: add --pre flagCharles Blake
The preprocessor flag accepts a command program and executes this program for every input file that is searched. Instead of searching the file directly, ripgrep will instead search the stdout contents of the program. Closes #978, Closes #981
2018-06-25ripgrep: rename --maxdepth to --max-depthdana
We keep the old `--maxdepth` spelling to preserve backward compatibility. PR #967
2018-06-23ripgrep: use new BufferedStandardStream from termcolorAndrew Gallant
Specifically, this will use a buffered writer when not printing to a tty. This fixes a long standing performance regression where ripgrep would slow down dramatically if it needed to report a lot of matches. Fixes #955
2018-04-23output: remove --line-number-width flagAndrew Gallant
This commit does what no software project has ever done before: we've outright removed a flag with no possible way to recapture its functionality. This flag presents numerous problems in that it never really worked well in the first place, and completely falls over when ripgrep uses the --no-heading output format. Well meaning users want ripgrep to fix this by getting into the alignment business by buffering all output, but that is a line that I refuse to cross. Fixes #795
2018-04-23output: add --no-column flagAndrew Gallant
This disables columns in the output if they were otherwise enabled. Fixes #880
2018-04-23logging: add new --no-ignore-messages flagAndrew Gallant
The new --no-ignore-messages flag permits suppressing errors related to parsing .gitignore or .ignore files. These error messages can be somewhat annoying since they can surface from repositories that one has no control over. Fixes #646
2018-03-13grep: upgrade to regex-syntax 0.5Andrew Gallant
This update brings with it many bug fixes: * Better error messages are printed overall. We also include explicit call out for unsupported features like backreferences and look-around. * Regexes like `\s*{` no longer emit incomprehensible errors. * Unicode escape sequences, such as `\u{..}` are now supported. For the most part, this upgrade was done in a straight-forward way. We resist the urge to refactor the `grep` crate, in anticipation of it being rewritten anyway. Note that we removed the `--fixed-strings` suggestion whenever a regex syntax error occurs. In practice, I've found that it results in a lot of false positives, and I believe that its use is not as paramount now that regex parse errors are much more readable. Closes #268, Closes #395, Closes #702, Closes #853
2018-03-12deps: update regex crateAndrew Gallant
This update brings with it a new feature of the regex crate which will now use SIMD optimizations automatically at runtime with no necessary compile time flags. All that's needed is to enable the `unstable` feature. Other crates, such as bytecount and encoding_rs, are still using the old-style SIMD support, so we leave the simd-accel and avx-accel features. However, the binaries we distribute on Github no longer have those features enabled, which makes them truly portable. Fixes #135
2018-03-10output: add --stats flagBalaji Sivaraman
This commit provides basic support for a --stats flag, which will print various aggregate statistics about a search after all of the results have been printed. This is mostly intended to support a similar feature found in the Silver Searcher. Note though that we don't emit the total bytes searched; this is a first pass at an implementation and we can improve upon it later. Closes #411, Closes #799
2018-03-10args: treat --count --only-matching as --count-matchesAndrew Gallant
Namely, when ripgrep is asked to count things and is also asked to print every match on its own line, then we should just automatically count the matches and not the lines. This is a departure from how GNU grep behaves, but there is a compelling argument to be made that GNU grep's behavior doesn't make a lot of sense. Note that since this changes the behavior of combining two existing flags, this is a breaking change.
2018-03-10search: add a --count-matches flagBalaji Sivaraman
This commit introduces a new flag, --count-matches, which will cause ripgrep to report a total count of all matches instead of a count of total lines matched. Closes #566, Closes #814
2018-03-10search: add -b/--byte-offset flagBalaji Sivaraman
This commit adds support for printing 0-based byte offset before each line. We handle corner cases such as `-o/--only-matching` and `-C/--context` as well. Closes #812
2018-02-06argv: tweak the meaning of zeroAndrew Gallant
This commit makes a small tweak to the --max-columns flag. Namely, if the value of the flag is 0, then ripgrep behaves as-if the flag were absent. This is useful in the context of ripgrep reading configuration from the environment. For example, an end user might set --max-columns=150, but we should permit the user to disable this setting when needed. Using -M0 is a nice way to do that. We do this because a zero value for --max-columns isn't particularly meaningful. We do leave the --max-count, --max-filesize and --maxdepth flags alone though, since a zero value for those flags is potentially meaningful. (--max-count even has tests for ripgrep's behavior when given a value of 0.)
2018-02-06argv: update clap to 2.29.4Andrew Gallant
We use the new AppSettings::AllArgsOverrideSelf to permit all flags to be specified multiple times. This removes the need for our previous work-around where we would enable `multiple` for every flag and then just extract the last value when consuming clap's matches. We also add a couple regression tests that ensure repeated switches and flags work as expected.
2018-02-04config: add persistent configurationAndrew Gallant
This commit adds support for reading configuration files that change ripgrep's default behavior. The format of the configuration file is an "rc" style and is very simple. It is defined by two rules: 1. Every line is a shell argument, after trimming ASCII whitespace. 2. Lines starting with '#' (optionally preceded by any amount of ASCII whitespace) are ignored. ripgrep will look for a single configuration file if and only if the RIPGREP_CONFIG_PATH environment variable is set and is non-empty. ripgrep will parse shell arguments from this file on startup and will behave as if the arguments in this file were prepended to any explicit arguments given to ripgrep on the command line. For example, if your ripgreprc file contained a single line: --smart-case then the following command RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo would behave identically to the following command rg --smart-case foo This commit also adds a new flag, --no-config, that when present will suppress any and all support for configuration. This includes any future support for auto-loading configuration files from pre-determined paths (which this commit does not add). Conflicts between configuration files and explicit arguments are handled exactly like conflicts in the same command line invocation. That is, this command: RIPGREP_CONFIG_PATH=wherever/.ripgreprc rg foo --case-sensitive is exactly equivalent to rg --smart-case foo --case-sensitive in which case, the --case-sensitive flag would override the --smart-case flag. Closes #196
2018-02-04argv: permit repeated flagsAndrew Gallant
This commit builds on the previous argv refactor by being more principled about how we declared our flags. In particular, we now require that every clap argument is one of three things: a positional argument, a switch or a flag that accepts exactly one value. The latter two are always permitted to be repeated, and we modify the code that consumes a clap::ArgMatches to always use the *last* value of an argument. (clap by default always uses the first value of argument, if it has been repeated and is accessed via one of the singleton accessors.) Fixes #553
2018-02-04logger: drop env_loggerAndrew Gallant
This commit updates the `log` crate to 0.4 and drops the dependency on env_logger. In particular, the latest version of env_logger brings in additional non-optional dependencies such as chrono that I don't think is worth including into ripgrep. It turns out ripgrep doesn't need any fancy logging. We just need a concept of log levels and the ability to print to stderr. Therefore, we just roll our own super simple logger. This update is motivated by the persistent configuration task. In particular, we need the ability to toggle the global log level more than once, and this doesn't appear to be possible with older versions of the log crate.
2018-02-01windows: fix OneDrive traversalsAndrew Gallant
This commit fixes a bug on Windows where directory traversals were completely broken when attempting to scan OneDrive directories that use the "file on demand" strategy. The specific problem was that Rust's standard library treats OneDrive directories as reparse points instead of directories, which causes methods like `FileType::is_file` and `FileType::is_dir` to always return false, even when retrieved via methods like `metadata` that purport to follow symbolic links. We fix this by peppering our code with checks on the underlying file attributes exposed by Windows. We consider an entry a directory if and only if the directory bit is set on the attributes. We are careful to make sure that the code remains the same on non-Windows platforms. Note that we also bump the dependency on `walkdir`, which contains a similar fix for its traversals. This bug is recorded upstream: https://github.com/rust-lang/rust/issues/46484 Upstream also has a pending PR: https://github.com/rust-lang/rust/pull/47956 Fixes #705
2018-01-30search: add support for searching compressed filesBalaji Sivaraman
This commit adds opt-in support for searching compressed files during recursive search. This behavior is only enabled when the `-z/--search-zip` flag is passed to ripgrep. When enabled, a limited set of common compression formats are recognized via file extension, and a new process is spawned to perform the decompression. ripgrep then searches the stdout of that spawned process. Closes #539
2018-01-29ignore: support custom file namesptzz
This commit adds support for ignore files with custom names. This allows for application specific ignorefile names, e.g. using `.fdignore` for `fd`. See also: https://github.com/BurntSushi/ripgrep/issues/673 See also: https://github.com/sharkdp/fd/issues/156