summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 7fbed15..33b170d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
use anyhow::Result;
use clap::Parser;
-use projectr::{project::Project, search::Search, Config};
+use projectr::{config::Config, path::PathMatcher, project::Project, search::SearchBuilder};
fn main() -> Result<()> {
let config = Config::parse();
@@ -11,7 +11,9 @@ fn main() -> Result<()> {
.with_max_level(&config.verbosity)
.init();
- let mut projects: Vec<Project> = Search::new(config).into_iter().collect();
+ let mut projects: Vec<Project> = build_search(&config)
+ .filter(|p| !config.paths.contains(&p.worktree))
+ .collect();
projects.sort_unstable_by_key(|p| p.timestamp);
@@ -21,3 +23,35 @@ fn main() -> Result<()> {
Ok(())
}
+
+fn build_search(config: &Config) -> impl Iterator<Item = Project> {
+ let (init, paths) = config.paths.split_first().unwrap();
+ let mut builder = SearchBuilder::new(init);
+
+ for path in paths {
+ builder.add(path);
+ }
+
+ for path in &config.projects {
+ builder.project(path);
+ }
+
+ builder.max_depth(config.search.max_depth);
+
+ builder.hidden(!config.search.hidden);
+
+ if config.search.parsers.all {
+ builder.parser(PathMatcher::All);
+ }
+
+ if let Some(pattern) = &config.search.parsers.pattern {
+ builder.parser(PathMatcher::Pattern(pattern.to_owned()));
+ }
+
+ #[cfg(feature = "git")]
+ if config.search.parsers.git {
+ builder.parser(projectr::git::Git);
+ }
+
+ builder.build()
+}