Skip to content

Commit

Permalink
Search hidden files and directories by default
Browse files Browse the repository at this point in the history
Fixes #6.
  • Loading branch information
vishaltelangre committed Feb 28, 2019
1 parent afcf61f commit e0407c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/app.rs
Expand Up @@ -31,10 +31,10 @@ pub fn app() -> ArgMatches<'static> {
.required(false),
)
.arg(
Arg::with_name("search-hidden")
.help("Search hidden files and directories. By default, hidden files and directories are skipped.")
Arg::with_name("ignore-hidden")
.help("Ignore searching hidden files and directories. By default, hidden files and directories are included in the search results.")
.short("H")
.long("search-hidden"),
.long("ignore-hidden"),
)
.arg(
Arg::with_name("case-sensitive")
Expand Down
8 changes: 4 additions & 4 deletions src/args.rs
Expand Up @@ -10,7 +10,7 @@ use crate::app;
pub struct Args {
pub reg_exp: Regex,
pub root_path: String,
pub search_hidden: bool,
pub ignore_hidden: bool,
pub case_sensitive: bool,
}

Expand All @@ -33,8 +33,8 @@ impl ArgMatchesWrapper {
self.matches.is_present("case-sensitive")
}

fn should_search_hidden_files(&self) -> bool {
self.matches.is_present("search-hidden")
fn should_ignore_hidden_files(&self) -> bool {
self.matches.is_present("ignore-hidden")
}

fn search_pattern(&self) -> Regex {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl ArgMatchesWrapper {
fn to_args(&self) -> Args {
Args {
root_path: self.root_path(),
search_hidden: self.should_search_hidden_files(),
ignore_hidden: self.should_ignore_hidden_files(),
case_sensitive: self.is_case_sensitive(),
reg_exp: self.search_pattern(),
}
Expand Down
8 changes: 4 additions & 4 deletions src/walker.rs
Expand Up @@ -19,20 +19,20 @@ impl<'a> Walker<'a> {
}

pub fn matching_paths(&self) -> Vec<String> {
let paths = self
let paths: Vec<String> = self
.accessible_paths()
.into_iter()
.map(|p| self.truncate_working_dir_path(p.path().display().to_string()))
.filter(|path| self.args.reg_exp.is_match(path))
.collect();

if self.args.search_hidden {
paths
} else {
if self.args.ignore_hidden {
paths
.into_iter()
.filter(|path| !path.contains("/."))
.collect()
} else {
paths
}
}

Expand Down

0 comments on commit e0407c5

Please sign in to comment.