From 46cee052d6d4b60b483ab6841af976d68d954705 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sat, 26 Nov 2022 16:43:14 -0600 Subject: feat: add project filtering --- src/projects/entry.rs | 76 --------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/projects/entry.rs (limited to 'src/projects/entry.rs') 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, -} - -impl SearchPath { - pub fn filter(dir_entry: &DirEntry) -> bool { - dir_entry.path().join(".git").exists() - } -} - -impl From for SearchPath { - fn from(path: PathBuf) -> Self { - Self { - path, - ..Default::default() - } - } -} - -impl From 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 { - s.parse().map(PathBuf::into) - } -} - -impl<'de> Deserialize<'de> for SearchPath { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - #[derive(Deserialize)] - #[serde(untagged)] - enum Variants { - String(String), - Struct { - path: PathBuf, - hidden: bool, - recurse: Option, - }, - } - - 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, - }), - } - } -} -- cgit v1.2.3-70-g09d2