summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-07-22 09:32:31 -0400
committerAndrew Gallant <jamslam@gmail.com>2018-07-22 09:33:03 -0400
commitb9c922be53fdadb28ddbb02b4b0d0a63f8bdebe7 (patch)
tree21e927aee8f21629405b33558f6fbfc1fb8067a2
parent7a44cad599d7602ccd4395136c14587c159a37a3 (diff)
ripgrep: better --path-separator error message
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
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/args.rs9
-rw-r--r--src/unescape.rs9
3 files changed, 19 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 99303c38..f4fafc5f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -87,6 +87,9 @@ Bug fixes:
* [BUG #955](https://github.com/BurntSushi/ripgrep/issues/955):
Use buffered writing when not printing to a tty, which fixes a performance
regression.
+* [BUG #957](https://github.com/BurntSushi/ripgrep/issues/957):
+ Improve the error message shown for `--path separator /` in some Windows
+ shells.
* [BUG #964](https://github.com/BurntSushi/ripgrep/issues/964):
Add a `--no-fixed-strings` flag to disable `-F/--fixed-strings`.
* [BUG #988](https://github.com/BurntSushi/ripgrep/issues/988):
diff --git a/src/args.rs b/src/args.rs
index 302e330e..7100fc5c 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -22,7 +22,7 @@ use ignore::overrides::{Override, OverrideBuilder};
use ignore::types::{FileTypeDef, Types, TypesBuilder};
use ignore;
use printer::{ColorSpecs, Printer};
-use unescape::unescape;
+use unescape::{escape, unescape};
use worker::{Worker, WorkerBuilder};
use config;
@@ -749,7 +749,12 @@ impl<'a> ArgMatches<'a> {
} 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())))
+ the given separator is {} bytes: {}\n\
+ In some shells on Windows '/' is automatically \
+ expanded. Use '//' instead.",
+ sep.len(),
+ escape(&sep),
+ )))
} else {
Ok(Some(sep[0]))
}
diff --git a/src/unescape.rs b/src/unescape.rs
index c27e6e28..0c7f1c8d 100644
--- a/src/unescape.rs
+++ b/src/unescape.rs
@@ -11,6 +11,15 @@ enum State {
Literal,
}
+/// Escapes an arbitrary byte slice such that it can be presented as a human
+/// readable string.
+pub fn escape(bytes: &[u8]) -> String {
+ use std::ascii::escape_default;
+
+ let escaped = bytes.iter().flat_map(|&b| escape_default(b)).collect();
+ String::from_utf8(escaped).unwrap()
+}
+
/// Unescapes a string given on the command line. It supports a limited set of
/// escape sequences:
///