aboutsummaryrefslogtreecommitdiffstats
path: root/src/search.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/search.rs')
-rw-r--r--src/search.rs77
1 files changed, 26 insertions, 51 deletions
diff --git a/src/search.rs b/src/search.rs
index 888179e..81049e9 100644
--- a/src/search.rs
+++ b/src/search.rs
@@ -1,92 +1,67 @@
use std::path::PathBuf;
-use clap::Args;
+use crate::{config::Filters, project::Project, Config};
-use crate::project::ProjectItem;
-
-use self::entry::SearchEntry;
+use self::entry::SearchPath;
pub mod entry;
type EntryIter = std::vec::IntoIter<PathBuf>;
-#[derive(Debug, Default, Clone, Args)]
+#[derive(Debug, Default, Clone)]
pub struct Search {
- /// Directory to search.
- ///
- /// Directories are searched recursively based on `--max-depth`.
pub paths: Vec<PathBuf>,
-
- #[command(flatten)]
- pub filter: Filters,
+ pub add: Vec<PathBuf>,
+ pub filters: Filters,
}
-#[derive(Debug, Default, Clone, Args)]
-pub struct Filters {
- /// Match all child directories
- #[arg(long, short, conflicts_with_all = ["pattern", "git"])]
- pub all: bool,
-
- /// Max depth to recurse.
- ///
- /// Setting to 0 will only use the supplied directory.
- #[arg(short = 'd', long, default_value = "1")]
- pub max_depth: Option<usize>,
-
- /// Recurse into hidden directories.
- ///
- /// Traverse into hidden directories while searching. A directory is considered hidden
- /// if its name starts with a `.` sign (dot). If `--max-depth` is 0, this has no effect.
- #[arg(long)]
- pub hidden: bool,
-
- /// Match directories containing item named <PATTERN>
- #[arg(long, short)]
- pub pattern: Option<String>,
-
- /// Match git repositories
- #[cfg(feature = "git")]
- #[arg(long, short, default_value_t = true)]
- pub git: bool,
+impl Search {
+ pub fn new(
+ Config {
+ paths,
+ add,
+ filters,
+ verbosity: _,
+ }: Config,
+ ) -> Self {
+ Self {
+ paths,
+ add,
+ filters,
+ }
+ }
}
impl IntoIterator for Search {
- type Item = ProjectItem;
+ type Item = Project;
type IntoIter = SearchIter;
fn into_iter(self) -> Self::IntoIter {
SearchIter {
iter: self.paths.into_iter(),
- config: self.filter,
+ config: self.filters,
curr: None,
}
}
}
+#[derive(Debug)]
pub struct SearchIter {
iter: EntryIter,
config: Filters,
- curr: Option<SearchEntry>,
-}
-
-impl std::fmt::Debug for SearchIter {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("Projects")
- .field("paths_iter", &self.iter)
- .finish_non_exhaustive()
- }
+ curr: Option<SearchPath>,
}
impl Iterator for SearchIter {
- type Item = ProjectItem;
+ type Item = Project;
#[tracing::instrument]
fn next(&mut self) -> Option<Self::Item> {
match self.curr.as_mut().and_then(|c| c.next()) {
Some(proj) => Some(proj),
None => {
- self.curr = Some(SearchEntry::new(self.iter.next()?, &self.config));
+ self.curr = Some(SearchPath::new(self.iter.next()?, &self.config));
self.next()
}
}