diff options
author | Andrew Gallant <jamslam@gmail.com> | 2017-01-10 18:16:15 -0500 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-01-10 18:16:15 -0500 |
commit | 8751e5570697e6b2b913b2ab06e0dabf9f28b436 (patch) | |
tree | 51a57c6e292aaa8dc74ec30635faf2ad9c509726 /src/args.rs | |
parent | 2143bcf9cb259c2230aa79a7cbc23cb1ec1fdae7 (diff) |
Add --path-separator flag.
This flag permits setting the path separator used for all file paths
printed by ripgrep in normal operation.
Fixes #275
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs index 29a7fa81..594ece09 100644 --- a/src/args.rs +++ b/src/args.rs @@ -62,6 +62,7 @@ pub struct Args { no_ignore_vcs: bool, no_messages: bool, null: bool, + path_separator: Option<u8>, quiet: bool, quiet_matched: QuietMatched, replace: Option<Vec<u8>>, @@ -151,6 +152,7 @@ impl Args { .heading(self.heading) .line_per_match(self.line_per_match) .null(self.null) + .path_separator(self.path_separator) .with_filename(self.with_filename); if let Some(ref rep) = self.replace { p = p.replace(rep.clone()); @@ -347,6 +349,7 @@ impl<'a> ArgMatches<'a> { no_ignore_vcs: self.no_ignore_vcs(), no_messages: self.is_present("no-messages"), null: self.is_present("null"), + path_separator: try!(self.path_separator()), quiet: quiet, quiet_matched: QuietMatched::new(quiet), replace: self.replace(), @@ -616,6 +619,25 @@ impl<'a> ArgMatches<'a> { } } + /// Returns the unescaped path separator in UTF-8 bytes. + fn path_separator(&self) -> Result<Option<u8>> { + match self.value_of_lossy("path-separator") { + None => Ok(None), + Some(sep) => { + let sep = unescape(&sep); + if sep.is_empty() { + Ok(None) + } else if sep.len() > 1 { + Err(From::from(format!( + "A path separator must be exactly one byte, but \ + the given separator is {} bytes.", sep.len()))) + } else { + Ok(Some(sep[0])) + } + } + } + } + /// Returns the before and after contexts from the command line. /// /// If a context setting was absent, then `0` is returned. |