diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 46 |
1 files changed, 6 insertions, 40 deletions
diff --git a/src/main.rs b/src/main.rs index 33b170d..bdc7998 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use anyhow::Result; use clap::Parser; -use projectr::{config::Config, path::PathMatcher, project::Project, search::SearchBuilder}; +use projectr::{config::Config, project::Projects, Search}; fn main() -> Result<()> { let config = Config::parse(); @@ -11,47 +11,13 @@ fn main() -> Result<()> { .with_max_level(&config.verbosity) .init(); - let mut projects: Vec<Project> = build_search(&config) - .filter(|p| !config.paths.contains(&p.worktree)) - .collect(); + let mut projects = Projects::from(config.parsers); - projects.sort_unstable_by_key(|p| p.timestamp); + projects.extend(config.projects); - for project in projects { - println!("{}", project.worktree.to_string_lossy()) + if let Ok(search) = Search::try_from(config.search) { + projects.extend(search); } - 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() + Ok(projects.write(std::io::stdout())?) } |