Add -i, --ignore-case

This commit is contained in:
J.W 2017-10-12 07:21:44 +08:00 committed by David Peter
parent 35e5ecd492
commit e075e1cf7c
4 changed files with 32 additions and 4 deletions

View File

@ -35,7 +35,8 @@ pub fn build_app() -> App<'static, 'static> {
.arg(arg("hidden").long("hidden").short("H"))
.arg(arg("no-ignore").long("no-ignore").short("I"))
.arg(arg("rg-alias-hidden-ignore").short("u").multiple(true).hidden(true))
.arg(arg("case-sensitive").long("case-sensitive").short("s"))
.arg(arg("case-sensitive").long("case-sensitive").short("s").overrides_with("ignore-case"))
.arg(arg("ignore-case").long("ignore-case").short("i").overrides_with("case-sensitive"))
.arg(arg("absolute-path").long("absolute-path").short("a"))
.arg(arg("follow").long("follow").short("L").alias("dereference"))
.arg(arg("full-path").long("full-path").short("p"))
@ -98,6 +99,10 @@ fn usage() -> HashMap<&'static str, Help> {
, "Case-sensitive search (default: smart case)"
, "Perform a case-sensitive search. By default, fd uses case-insensitive searches, \
unless the pattern contains both upper- and lowercase characters (smart case).");
doc!(h, "ignore-case"
, "Case-insensitive search (default: smart case)"
, "Perform a case-insensitive search. By default, fd uses case-insensitive searches, \
unless the pattern contains both upper- and lowercase characters (smart case).");
doc!(h, "absolute-path"
, "Show absolute instead of relative paths"
, "Shows the full path starting from the root as opposed to relative paths.");

View File

@ -24,7 +24,7 @@ pub enum PathDisplay {
/// Configuration options for *fd*.
pub struct FdOptions {
/// Determines whether the regex search is case-sensitive or case-insensitive.
/// Whether the search is case-sensitive or case-insensitive.
pub case_sensitive: bool,
/// Whether to search within the full file path or just the base name (filename or directory

View File

@ -62,8 +62,11 @@ fn main() {
// The search will be case-sensitive if the command line flag is set or
// if the pattern has an uppercase character (smart case).
let case_sensitive = matches.is_present("case-sensitive") ||
pattern.chars().any(char::is_uppercase);
let case_sensitive = if !matches.is_present("ignore-case") {
matches.is_present("case-sensitive") || pattern.chars().any(char::is_uppercase)
} else {
false
};
let colored_output = match matches.value_of("color") {
Some("always") => true,

View File

@ -115,6 +115,26 @@ fn test_case_sensitive() {
te.assert_output(
&["--case-sensitive", "C.Foo"],
"one/two/C.Foo2");
te.assert_output(
&["--ignore-case", "--case-sensitive", "C.Foo"],
"one/two/C.Foo2");
}
/// Case insensitivity (--ignore-case)
#[test]
fn test_case_insensitive() {
let te = TestEnv::new();
te.assert_output(
&["--ignore-case", "C.Foo"],
"one/two/c.foo
one/two/C.Foo2");
te.assert_output(
&["--case-sensitive", "--ignore-case", "C.Foo"],
"one/two/c.foo
one/two/C.Foo2");
}
/// Full path search (--full-path)