use ignore::{DirEntry, Walk}; use tracing::error; use crate::project::{GitProject, PathProject, ProjectItem}; pub use config::Config; mod config; pub struct Entry { config: Config, iter: Walk, } impl std::fmt::Debug for Entry { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("SearchPath") .field("config", &self.config) .finish() } } impl Entry { pub fn parse_dir_entry(&self, dir_entry: DirEntry) -> Option { if self.config.git { if let Ok(git) = GitProject::try_from(dir_entry.to_owned()) { return Some(Box::new(git)); }; }; if let Some(pattern) = &self.config.pattern { if let Ok(proj) = PathProject::try_from((pattern, dir_entry)) { return Some(Box::new(proj)); }; }; None } } impl Iterator for Entry { type Item = ProjectItem; #[tracing::instrument] fn next(&mut self) -> Option { match self.iter.next()? { Ok(dir_entry) => self.parse_dir_entry(dir_entry), Err(err) => { error!(%err, "Ignoring errored path"); self.next() } } } }