aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-05-04 19:43:08 -0500
committerToby Vincent <tobyv13@gmail.com>2023-05-04 19:43:08 -0500
commit5da4fb25f9bb72771c7f2798daa6339be0bc3900 (patch)
treec30639c7a95e1d94baff498d247eed43fdb3728e /src/main.rs
parent589cd987217755e1da7acbc304c373a75a9f7db5 (diff)
refactor: join iterators into a single walk
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()
+}