summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs56
1 files changed, 47 insertions, 9 deletions
diff --git a/src/config.rs b/src/config.rs
index 126b939..e73b7e1 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,11 +1,12 @@
use figment::{providers::Serialized, value, Figment, Metadata, Profile, Provider};
use serde::{Deserialize, Serialize};
+use std::{convert::Infallible, path::PathBuf, str::FromStr};
-use crate::search;
-
+#[serde_with::serde_as]
#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
pub struct Config {
- pub(crate) paths: Vec<search::entry::Config>,
+ #[serde_as(as = "Vec<serde_with::PickFirst<(_, serde_with::DisplayFromStr)>>")]
+ pub(crate) paths: Vec<Entry>,
}
impl Config {
@@ -30,6 +31,43 @@ impl Provider for Config {
}
}
+#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
+#[serde(default)]
+pub struct Entry {
+ pub path_buf: PathBuf,
+ pub hidden: bool,
+ pub max_depth: Option<usize>,
+ pub pattern: Option<String>,
+ #[cfg(feature = "git")]
+ pub git: bool,
+}
+
+impl Entry {
+ pub fn new(path_buf: PathBuf) -> Self {
+ Self {
+ path_buf,
+ ..Default::default()
+ }
+ }
+}
+
+impl From<PathBuf> for Entry {
+ fn from(path_buf: PathBuf) -> Self {
+ Self::new(path_buf)
+ }
+}
+
+impl FromStr for Entry {
+ type Err = Infallible;
+
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
+ s.parse().map(|path_buf| Self {
+ path_buf,
+ ..Default::default()
+ })
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -37,15 +75,15 @@ mod tests {
use pretty_assertions::assert_eq;
#[test]
- fn test_extract() {
+ fn test_extract_config() {
figment::Jail::expect_with(|jail| {
jail.create_file(
"file.toml",
r#"
paths = [
"/path/to/projects",
- { path = "/path/to/other_projects", recurse = 1, hidden = true },
- { path = "/path/to/another_project", recurse = 0 },
+ { path_buf = "/path/to/other_projects", hidden = true, max_depth = 1 },
+ { path_buf = "/path/to/another_project", max_depth = 0 }
]
"#,
)?;
@@ -58,19 +96,19 @@ mod tests {
config,
Config {
paths: Vec::from([
- search::entry::Config {
+ Entry {
path_buf: "/path/to/projects".into(),
hidden: false,
max_depth: None,
..Default::default()
},
- search::entry::Config {
+ Entry {
path_buf: "/path/to/other_projects".into(),
hidden: true,
max_depth: Some(1),
..Default::default()
},
- search::entry::Config {
+ Entry {
path_buf: "/path/to/another_project".into(),
hidden: false,
max_depth: Some(0),