From a1489c5981fb1cdbf8a746b51fa310922d78b014 Mon Sep 17 00:00:00 2001 From: Adrian Covaci <6562353+acovaci@users.noreply.github.com> Date: Sat, 25 May 2024 13:14:53 +0100 Subject: [PATCH] fix(project): Now projects are within their default dirs, not the dirs themselves --- src/cli/project.rs | 24 +++++++++++++++++++++--- src/core/config/project.rs | 8 +------- src/core/config/transcriber.rs | 2 +- tests/fixtures/manager_load.yml | 5 ----- tests/fixtures/project_list.yml | 15 +++++++++++++++ tests/fixtures/transcriber_dump.yml | 6 +++--- tests/fixtures/transcriber_load.yml | 4 ++-- 7 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 tests/fixtures/project_list.yml diff --git a/src/cli/project.rs b/src/cli/project.rs index 790358a..7d2f707 100644 --- a/src/cli/project.rs +++ b/src/cli/project.rs @@ -30,19 +30,37 @@ fn get_projects(config: ConfigManager) -> Res> { #[cfg(test)] mod tests { + use std::path::PathBuf; + use super::*; use plumb::types::Location; #[test] fn test_get_projects() { - let config = ConfigManager::try_load(None).unwrap(); + let config = + ConfigManager::try_load(Some(&PathBuf::from("tests/fixtures/project_list.yml"))) + .unwrap(); let projects = get_projects(config).unwrap(); assert_eq!( projects, vec![ - Project::new("plumb", Location::new("~/projects/plumb".into(), None)), - Project::new("monad", Location::new("~/projects/monad".into(), None)) + Project::new( + "project1", + Location::new("~/projects/project1".into(), None) + ), + Project::new( + "project2", + Location::new("~/other_projects/project2".into(), None) + ), + Project::new( + "project3", + Location::new("~/projects/project3".into(), None) + ), + Project::new( + "project4", + Location::new("~/projects/project4".into(), None) + ) ] ); } diff --git a/src/core/config/project.rs b/src/core/config/project.rs index becd593..1df1230 100644 --- a/src/core/config/project.rs +++ b/src/core/config/project.rs @@ -12,12 +12,6 @@ impl ProjectBuilder { } pub fn build(&self, name: &str, location: Option) -> Project { - Project::new( - name, - location.unwrap_or({ - let path = self.location.path().join(name); - Location::new(path, None) - }), - ) + Project::new(name, location.unwrap_or(self.location.join(name))) } } diff --git a/src/core/config/transcriber.rs b/src/core/config/transcriber.rs index 01589ef..9bb633c 100644 --- a/src/core/config/transcriber.rs +++ b/src/core/config/transcriber.rs @@ -103,7 +103,7 @@ impl ConfigTranscriber for PlumbConfig { Location::new( project .path - .unwrap_or(default_project_location.clone().path().to_path_buf()), + .unwrap_or(default_project_location.join(&project.name).path().clone()), None, ), ) diff --git a/tests/fixtures/manager_load.yml b/tests/fixtures/manager_load.yml index 3b05c04..1949415 100644 --- a/tests/fixtures/manager_load.yml +++ b/tests/fixtures/manager_load.yml @@ -4,17 +4,12 @@ locations: - path: ~/projects name: projects - path: ~/other_projects - name: - path: ~/yet_another_projects - name: defaults: projects: projects projects: - name: project1 - path: - name: project2 path: ~/other_projects/project2 - name: project3 - path: - name: project4 - path: diff --git a/tests/fixtures/project_list.yml b/tests/fixtures/project_list.yml new file mode 100644 index 0000000..1949415 --- /dev/null +++ b/tests/fixtures/project_list.yml @@ -0,0 +1,15 @@ +--- +locations: + projects: + - path: ~/projects + name: projects + - path: ~/other_projects + - path: ~/yet_another_projects + defaults: + projects: projects +projects: + - name: project1 + - name: project2 + path: ~/other_projects/project2 + - name: project3 + - name: project4 diff --git a/tests/fixtures/transcriber_dump.yml b/tests/fixtures/transcriber_dump.yml index 415cf0d..b65bdab 100644 --- a/tests/fixtures/transcriber_dump.yml +++ b/tests/fixtures/transcriber_dump.yml @@ -11,10 +11,10 @@ locations: projects: projects projects: - name: project1 - path: ~/projects + path: ~/projects/project1 - name: project2 path: ~/other_projects/project2 - name: project3 - path: ~/projects + path: ~/projects/project3 - name: project4 - path: ~/projects + path: ~/projects/project4 diff --git a/tests/fixtures/transcriber_load.yml b/tests/fixtures/transcriber_load.yml index 47b0f7f..dcef115 100644 --- a/tests/fixtures/transcriber_load.yml +++ b/tests/fixtures/transcriber_load.yml @@ -1,10 +1,10 @@ --- locations: projects: - - path: ~/projects - name: projects - path: ~/other_projects name: + - path: ~/projects + name: projects - path: ~/yet_another_projects name: defaults: