diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-11-26 16:43:14 -0600 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-11-26 16:43:14 -0600 |
commit | 46cee052d6d4b60b483ab6841af976d68d954705 (patch) | |
tree | 19bbe2170c5a2e6af3b306e14c942ccd1393228a /src/projects/entry.rs | |
parent | 0f428974b2d7f4cf59490904564e52d134b9ef3a (diff) |
feat: add project filtering
Diffstat (limited to 'src/projects/entry.rs')
-rw-r--r-- | src/projects/entry.rs | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/projects/entry.rs b/src/projects/entry.rs deleted file mode 100644 index 739ed83..0000000 --- a/src/projects/entry.rs +++ /dev/null @@ -1,76 +0,0 @@ -use ignore::{DirEntry, Walk, WalkBuilder}; -use serde::{Deserialize, Deserializer, Serialize}; -use std::{convert::Infallible, path::PathBuf, str::FromStr}; - -#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize)] -#[serde(default)] -pub struct SearchPath { - pub path: PathBuf, - pub hidden: bool, - pub max_depth: Option<usize>, -} - -impl SearchPath { - pub fn filter(dir_entry: &DirEntry) -> bool { - dir_entry.path().join(".git").exists() - } -} - -impl From<PathBuf> for SearchPath { - fn from(path: PathBuf) -> Self { - Self { - path, - ..Default::default() - } - } -} - -impl From<SearchPath> for Walk { - fn from(value: SearchPath) -> Self { - WalkBuilder::new(value.path) - .standard_filters(true) - .max_depth(value.max_depth) - .hidden(!value.hidden) - .filter_entry(SearchPath::filter) - .build() - } -} - -impl FromStr for SearchPath { - type Err = Infallible; - - fn from_str(s: &str) -> Result<Self, Self::Err> { - s.parse().map(PathBuf::into) - } -} - -impl<'de> Deserialize<'de> for SearchPath { - fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> - where - D: Deserializer<'de>, - { - #[derive(Deserialize)] - #[serde(untagged)] - enum Variants { - String(String), - Struct { - path: PathBuf, - hidden: bool, - recurse: Option<usize>, - }, - } - - match Variants::deserialize(deserializer)? { - Variants::String(s) => s.parse().map_err(serde::de::Error::custom), - Variants::Struct { - path, - hidden, - recurse, - } => Ok(Self { - path, - hidden, - max_depth: recurse, - }), - } - } -} |