mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-06-30 22:23:44 +02:00
search: add -b/--byte-offset flag
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
This commit is contained in:
committed by
Andrew Gallant
parent
91d0756f62
commit
b006943c01
13
src/app.rs
13
src/app.rs
@ -509,6 +509,7 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
|
||||
// Flags can be defined in any order, but we do it alphabetically.
|
||||
flag_after_context(&mut args);
|
||||
flag_before_context(&mut args);
|
||||
flag_byte_offset(&mut args);
|
||||
flag_case_sensitive(&mut args);
|
||||
flag_color(&mut args);
|
||||
flag_colors(&mut args);
|
||||
@ -634,6 +635,18 @@ This overrides the --context flag.
|
||||
args.push(arg);
|
||||
}
|
||||
|
||||
fn flag_byte_offset(args: &mut Vec<RGArg>) {
|
||||
const SHORT: &str = "Print the 0-based byte offset for each matching line.";
|
||||
const LONG: &str = long!("\
|
||||
Print the 0-based byte offset within the input file
|
||||
before each line of output. If -o (--only-matching) is
|
||||
specified, print the offset of the matching part itself.
|
||||
");
|
||||
let arg = RGArg::switch("byte-offset").short("b")
|
||||
.help(SHORT).long_help(LONG);
|
||||
args.push(arg);
|
||||
}
|
||||
|
||||
fn flag_case_sensitive(args: &mut Vec<RGArg>) {
|
||||
const SHORT: &str = "Search case sensitively (default).";
|
||||
const LONG: &str = long!("\
|
||||
|
Reference in New Issue
Block a user