aboutsummaryrefslogtreecommitdiffstats
path: root/src/paths
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-11-21 14:26:02 -0600
committerToby Vincent <tobyv13@gmail.com>2022-11-21 14:26:02 -0600
commit72e9765d58b87125bdd5a2664bbc58202bdedff7 (patch)
tree656f7e2c46f8ca936439538d306f84409690946d /src/paths
parentfe92d86fbe5f73bc2662a128b6431ec2089d05b8 (diff)
chore: split out projectr from tmuxr
Diffstat (limited to 'src/paths')
-rw-r--r--src/paths/config.rs82
-rw-r--r--src/paths/error.rs10
-rw-r--r--src/paths/path_entry.rs59
3 files changed, 0 insertions, 151 deletions
diff --git a/src/paths/config.rs b/src/paths/config.rs
deleted file mode 100644
index 1e9bc65..0000000
--- a/src/paths/config.rs
+++ /dev/null
@@ -1,82 +0,0 @@
-use super::PathEntry;
-use figment::{providers::Serialized, value, Figment, Metadata, Profile, Provider};
-use serde::{Deserialize, Serialize};
-
-#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)]
-pub struct Config {
- pub(crate) paths: Vec<PathEntry>,
-}
-
-impl Config {
- // Extract the configuration from any `Provider`
- pub fn extract<T: Provider>(provider: T) -> figment::error::Result<Config> {
- Figment::from(provider).extract()
- }
-
- // Provide a default provider, a `Figment`.
- pub fn figment() -> Figment {
- Figment::from(Config::default())
- }
-}
-
-impl Provider for Config {
- fn metadata(&self) -> Metadata {
- Metadata::named("Tmuxr path config")
- }
-
- fn data(&self) -> figment::error::Result<value::Map<Profile, value::Dict>> {
- Serialized::defaults(self).data()
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
- use figment::providers::{Format, Serialized, Toml};
- use pretty_assertions::assert_eq;
-
- #[test]
- fn test_extract() {
- figment::Jail::expect_with(|jail| {
- jail.create_file(
- "tmuxr.toml",
- r#"
- paths = [
- "/path/to/projects",
- { path = "/path/to/other_projects", recurse = 1, hidden = true },
- { path = "/path/to/another_project", recurse = 0 },
- ]
- "#,
- )?;
-
- let config: Config = Figment::from(Serialized::defaults(Config::default()))
- .merge(Toml::file("tmuxr.toml"))
- .extract()?;
-
- assert_eq!(
- config,
- Config {
- paths: Vec::from([
- PathEntry {
- path: "/path/to/projects".into(),
- hidden: false,
- recurse: None,
- },
- PathEntry {
- path: "/path/to/other_projects".into(),
- hidden: true,
- recurse: Some(1),
- },
- PathEntry {
- path: "/path/to/another_project".into(),
- hidden: false,
- recurse: Some(0),
- },
- ]),
- }
- );
-
- Ok(())
- });
- }
-}
diff --git a/src/paths/error.rs b/src/paths/error.rs
deleted file mode 100644
index 4300e8a..0000000
--- a/src/paths/error.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-pub type Result<T> = std::result::Result<T, Error>;
-
-#[derive(thiserror::Error, Debug)]
-pub enum Error {
- #[error(transparent)]
- Config(#[from] figment::error::Error),
-
- #[error(transparent)]
- Ignore(#[from] ignore::Error),
-}
diff --git a/src/paths/path_entry.rs b/src/paths/path_entry.rs
deleted file mode 100644
index b050009..0000000
--- a/src/paths/path_entry.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-use serde::{Deserialize, Deserializer, Serialize};
-use std::{convert::Infallible, path::PathBuf, str::FromStr};
-
-#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize)]
-pub struct PathEntry {
- pub path: PathBuf,
- pub hidden: bool,
- pub recurse: Option<usize>,
-}
-
-impl From<PathBuf> for PathEntry {
- fn from(path: PathBuf) -> Self {
- Self {
- path,
- ..Default::default()
- }
- }
-}
-
-impl FromStr for PathEntry {
- type Err = Infallible;
-
- fn from_str(s: &str) -> Result<Self, Self::Err> {
- s.parse().map(PathBuf::into)
- }
-}
-
-impl<'de> Deserialize<'de> for PathEntry {
- fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
- where
- D: Deserializer<'de>,
- {
- #[derive(Deserialize)]
- #[serde(untagged)]
- enum Variants {
- String(String),
- Struct {
- path: PathBuf,
- #[serde(default)]
- hidden: bool,
- #[serde(default)]
- 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,
- recurse,
- }),
- }
- }
-}