mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-07-25 09:11:57 -07:00
ripgrep: add --pcre2-version flag
This flag will output details about the version of PCRE2 that ripgrep is using (if any).
This commit is contained in:
@@ -53,6 +53,8 @@ Feature enhancements:
|
||||
ripgrep's exit status logic should now match GNU grep. See updated man page.
|
||||
* [FEATURE #1170](https://github.com/BurntSushi/ripgrep/pull/1170):
|
||||
Add `--ignore-file-case-insensitive` for case insensitive .ignore globs.
|
||||
* FEATURE:
|
||||
Add `--pcre2-version` for querying showing PCRE2 version information.
|
||||
|
||||
Bug fixes:
|
||||
|
||||
|
@@ -43,6 +43,7 @@ _rg() {
|
||||
+ '(exclusive)' # Misc. fully exclusive options
|
||||
'(: * -)'{-h,--help}'[display help information]'
|
||||
'(: * -)'{-V,--version}'[display version information]'
|
||||
'(: * -)'--pcre2-version'[print the version of PCRE2 used by ripgrep, if available]'
|
||||
|
||||
+ '(buffered)' # buffering options
|
||||
'--line-buffered[force line buffering]'
|
||||
|
15
src/app.rs
15
src/app.rs
@@ -605,6 +605,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
|
||||
flag_path_separator(&mut args);
|
||||
flag_passthru(&mut args);
|
||||
flag_pcre2(&mut args);
|
||||
flag_pcre2_version(&mut args);
|
||||
flag_pre(&mut args);
|
||||
flag_pre_glob(&mut args);
|
||||
flag_pretty(&mut args);
|
||||
@@ -651,7 +652,7 @@ will be provided. Namely, the following is equivalent to the above:
|
||||
let arg = RGArg::positional("pattern", "PATTERN")
|
||||
.help(SHORT).long_help(LONG)
|
||||
.required_unless(&[
|
||||
"file", "files", "regexp", "type-list",
|
||||
"file", "files", "regexp", "type-list", "pcre2-version",
|
||||
]);
|
||||
args.push(arg);
|
||||
}
|
||||
@@ -1946,6 +1947,18 @@ This flag can be disabled with --no-pcre2.
|
||||
args.push(arg);
|
||||
}
|
||||
|
||||
fn flag_pcre2_version(args: &mut Vec<RGArg>) {
|
||||
const SHORT: &str = "Print the version of PCRE2 that ripgrep uses.";
|
||||
const LONG: &str = long!("\
|
||||
When this flag is present, ripgrep will print the version of PCRE2 in use,
|
||||
along with other information, and then exit. If PCRE2 is not available, then
|
||||
ripgrep will print an error message and exit with an error code.
|
||||
");
|
||||
let arg = RGArg::switch("pcre2-version")
|
||||
.help(SHORT).long_help(LONG);
|
||||
args.push(arg);
|
||||
}
|
||||
|
||||
fn flag_pre(args: &mut Vec<RGArg>) {
|
||||
const SHORT: &str = "search outputs of COMMAND FILE for each FILE";
|
||||
const LONG: &str = long!("\
|
||||
|
17
src/args.rs
17
src/args.rs
@@ -73,6 +73,8 @@ pub enum Command {
|
||||
/// List all file type definitions configured, including the default file
|
||||
/// types and any additional file types added to the command line.
|
||||
Types,
|
||||
/// Print the version of PCRE2 in use.
|
||||
PCRE2Version,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
@@ -82,7 +84,11 @@ impl Command {
|
||||
|
||||
match *self {
|
||||
Search | SearchParallel => true,
|
||||
SearchNever | Files | FilesParallel | Types => false,
|
||||
| SearchNever
|
||||
| Files
|
||||
| FilesParallel
|
||||
| Types
|
||||
| PCRE2Version => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +241,9 @@ impl Args {
|
||||
let threads = self.matches().threads()?;
|
||||
let one_thread = is_one_search || threads == 1;
|
||||
|
||||
Ok(if self.matches().is_present("type-list") {
|
||||
Ok(if self.matches().is_present("pcre2-version") {
|
||||
Command::PCRE2Version
|
||||
} else if self.matches().is_present("type-list") {
|
||||
Command::Types
|
||||
} else if self.matches().is_present("files") {
|
||||
if one_thread {
|
||||
@@ -685,8 +693,8 @@ impl ArgMatches {
|
||||
.word(self.is_present("word-regexp"));
|
||||
// For whatever reason, the JIT craps out during regex compilation with
|
||||
// a "no more memory" error on 32 bit systems. So don't use it there.
|
||||
if !cfg!(target_pointer_width = "32") {
|
||||
builder.jit_if_available(true);
|
||||
if cfg!(target_pointer_width = "64") {
|
||||
}
|
||||
if self.pcre2_unicode() {
|
||||
builder.utf(true).ucp(true);
|
||||
@@ -1278,7 +1286,8 @@ impl ArgMatches {
|
||||
!cli::is_readable_stdin()
|
||||
|| (self.is_present("file") && file_is_stdin)
|
||||
|| self.is_present("files")
|
||||
|| self.is_present("type-list");
|
||||
|| self.is_present("type-list")
|
||||
|| self.is_present("pcre2-version");
|
||||
if search_cwd {
|
||||
Path::new("./").to_path_buf()
|
||||
} else {
|
||||
|
28
src/main.rs
28
src/main.rs
@@ -39,6 +39,7 @@ fn try_main(args: Args) -> Result<()> {
|
||||
Files => files(&args),
|
||||
FilesParallel => files_parallel(&args),
|
||||
Types => types(&args),
|
||||
PCRE2Version => pcre2_version(&args),
|
||||
}?;
|
||||
if matched && (args.quiet() || !messages::errored()) {
|
||||
process::exit(0)
|
||||
@@ -275,3 +276,30 @@ fn types(args: &Args) -> Result<bool> {
|
||||
}
|
||||
Ok(count > 0)
|
||||
}
|
||||
|
||||
/// The top-level entry point for --pcre2-version.
|
||||
fn pcre2_version(args: &Args) -> Result<bool> {
|
||||
#[cfg(feature = "pcre2")]
|
||||
fn imp(args: &Args) -> Result<bool> {
|
||||
use grep::pcre2;
|
||||
|
||||
let mut stdout = args.stdout();
|
||||
|
||||
let (major, minor) = pcre2::version();
|
||||
writeln!(stdout, "PCRE2 {}.{} is available", major, minor)?;
|
||||
|
||||
if cfg!(target_pointer_width = "64") && pcre2::is_jit_available() {
|
||||
writeln!(stdout, "JIT is available")?;
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "pcre2"))]
|
||||
fn imp(args: &Args) -> Result<bool> {
|
||||
let mut stdout = args.stdout();
|
||||
writeln!(stdout, "PCRE2 is not available in this build of ripgrep.")?;
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
imp(args)
|
||||
}
|
||||
|
Reference in New Issue
Block a user