summaryrefslogtreecommitdiffstats
path: root/src/paths/config.rs
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/config.rs
parentfe92d86fbe5f73bc2662a128b6431ec2089d05b8 (diff)
chore: split out projectr from tmuxr
Diffstat (limited to 'src/paths/config.rs')
-rw-r--r--src/paths/config.rs82
1 files changed, 0 insertions, 82 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(())
- });
- }
-}