diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-11-22 15:20:18 -0600 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-11-22 15:20:18 -0600 |
commit | 8c4e03340a39a966a06bdce0c948b5462774d020 (patch) | |
tree | 219cd883e757ddef446f921b0cf298c48a6df24f /src/projects | |
parent | 72e9765d58b87125bdd5a2664bbc58202bdedff7 (diff) |
refactor: improve cli and config parsing
Diffstat (limited to 'src/projects')
-rw-r--r-- | src/projects/entry.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/projects/entry.rs b/src/projects/entry.rs index 86c23b4..08ed07a 100644 --- a/src/projects/entry.rs +++ b/src/projects/entry.rs @@ -1,11 +1,13 @@ +use ignore::{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 recurse: Option<usize>, + pub max_depth: Option<usize>, } impl From<PathBuf> for SearchPath { @@ -17,6 +19,16 @@ impl From<PathBuf> for SearchPath { } } +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) + .build() + } +} + impl FromStr for SearchPath { type Err = Infallible; @@ -36,9 +48,7 @@ impl<'de> Deserialize<'de> for SearchPath { String(String), Struct { path: PathBuf, - #[serde(default)] hidden: bool, - #[serde(default)] recurse: Option<usize>, }, } @@ -52,7 +62,7 @@ impl<'de> Deserialize<'de> for SearchPath { } => Ok(Self { path, hidden, - recurse, + max_depth: recurse, }), } } |