diff options
Diffstat (limited to 'src/search')
-rw-r--r-- | src/search/entry.rs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/src/search/entry.rs b/src/search/entry.rs index eb845e1..16dcd8b 100644 --- a/src/search/entry.rs +++ b/src/search/entry.rs @@ -1,11 +1,11 @@ +use std::path::PathBuf; + use ignore::{Walk, WalkBuilder}; use tracing::error; -use crate::{ - config::SearchEntryConfig, - project::{path::PathMatcher, ProjectParser, ProjectParserGroup}, - search::ProjectItem, -}; +use crate::project::{path::PathMatcher, ProjectItem, ProjectParser, ProjectParserGroup}; + +use super::Filters; pub struct SearchEntry { parsers: ProjectParserGroup, @@ -13,17 +13,15 @@ pub struct SearchEntry { } impl SearchEntry { - fn new(config: &SearchEntryConfig) -> Self { - let iter = WalkBuilder::new(&config.path_buf) - .standard_filters(true) - .max_depth(config.max_depth) - .hidden(!config.hidden) - .build(); - + pub fn new(path_buf: PathBuf, config: &Filters) -> Self { let mut parsers = ProjectParserGroup::new(); + if config.all { + parsers.push(Box::new(PathMatcher::All(path_buf.to_owned()))) + } + if let Some(s) = config.pattern.as_ref() { - parsers.push(Box::new(PathMatcher(s.to_owned()))); + parsers.push(Box::new(PathMatcher::Pattern(s.to_owned()))); }; #[cfg(feature = "git")] @@ -31,13 +29,13 @@ impl SearchEntry { parsers.push(Box::new(crate::project::git::GitMatcher)); }; - Self { parsers, iter } - } -} + let iter = WalkBuilder::new(path_buf) + .standard_filters(true) + .max_depth(config.max_depth) + .hidden(!config.hidden) + .build(); -impl From<SearchEntryConfig> for SearchEntry { - fn from(config: SearchEntryConfig) -> Self { - Self::new(&config) + Self { parsers, iter } } } |