summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/core/app.rs34
-rw-r--r--crates/core/args.rs22
2 files changed, 54 insertions, 2 deletions
diff --git a/crates/core/app.rs b/crates/core/app.rs
index dd9ae2cd..5058c0ea 100644
--- a/crates/core/app.rs
+++ b/crates/core/app.rs
@@ -568,6 +568,8 @@ pub fn all_args_and_flags() -> Vec<RGArg> {
flag_dfa_size_limit(&mut args);
flag_encoding(&mut args);
flag_engine(&mut args);
+ flag_field_context_separator(&mut args);
+ flag_field_match_separator(&mut args);
flag_file(&mut args);
flag_files(&mut args);
flag_files_with_matches(&mut args);
@@ -1231,6 +1233,38 @@ This overrides previous uses of --pcre2 and --auto-hybrid-regex flags.
args.push(arg);
}
+fn flag_field_context_separator(args: &mut Vec<RGArg>) {
+ const SHORT: &str = "Set the field context separator.";
+ const LONG: &str = long!(
+ "\
+Set the field context separator, which is used to delimit file paths, line
+numbers, columns and the context itself, when printing contextual lines. The
+separator may be any number of bytes, including zero. Escape sequences like
+\\x7F or \\t may be used. The default value is -.
+"
+ );
+ let arg = RGArg::flag("field-context-separator", "SEPARATOR")
+ .help(SHORT)
+ .long_help(LONG);
+ args.push(arg);
+}
+
+fn flag_field_match_separator(args: &mut Vec<RGArg>) {
+ const SHORT: &str = "Set the match separator.";
+ const LONG: &str = long!(
+ "\
+Set the field match separator, which is used to delimit file paths, line
+numbers, columns and the match itself. The separator may be any number of
+bytes, including zero. Escape sequences like \\x7F or \\t may be used. The
+default value is -.
+"
+ );
+ let arg = RGArg::flag("field-match-separator", "SEPARATOR")
+ .help(SHORT)
+ .long_help(LONG);
+ args.push(arg);
+}
+
fn flag_file(args: &mut Vec<RGArg>) {
const SHORT: &str = "Search for patterns from the given file.";
const LONG: &str = long!(
diff --git a/crates/core/args.rs b/crates/core/args.rs
index 7a448362..caa378bd 100644
--- a/crates/core/args.rs
+++ b/crates/core/args.rs
@@ -786,8 +786,8 @@ impl ArgMatches {
.trim_ascii(self.is_present("trim"))
.separator_search(None)
.separator_context(self.context_separator())
- .separator_field_match(b":".to_vec())
- .separator_field_context(b"-".to_vec())
+ .separator_field_match(self.field_match_separator())
+ .separator_field_context(self.field_context_separator())
.separator_path(self.path_separator()?)
.path_terminator(self.path_terminator());
if separator_search {
@@ -1377,6 +1377,24 @@ impl ArgMatches {
}
}
+ /// Returns the unescaped field context separator. If one wasn't specified,
+ /// then '-' is used as the default.
+ fn field_context_separator(&self) -> Vec<u8> {
+ match self.value_of_os("field-context-separator") {
+ None => b"-".to_vec(),
+ Some(sep) => cli::unescape_os(&sep),
+ }
+ }
+
+ /// Returns the unescaped field match separator. If one wasn't specified,
+ /// then ':' is used as the default.
+ fn field_match_separator(&self) -> Vec<u8> {
+ match self.value_of_os("field-match-separator") {
+ None => b":".to_vec(),
+ Some(sep) => cli::unescape_os(&sep),
+ }
+ }
+
/// Get a sequence of all available patterns from the command line.
/// This includes reading the -e/--regexp and -f/--file flags.
///