Skip to main content

git_same/config/
workspace_manager.rs

1//! Workspace manager facade.
2//!
3//! Keeps a stable API while delegating to `WorkspaceStore` and `WorkspacePolicy`.
4
5use super::workspace::WorkspaceConfig;
6use super::{workspace_policy::WorkspacePolicy, workspace_store::WorkspaceStore};
7use crate::errors::AppError;
8use std::path::{Path, PathBuf};
9
10/// Compatibility facade for workspace operations.
11pub struct WorkspaceManager;
12
13impl WorkspaceManager {
14    /// List all workspace configs.
15    pub fn list() -> Result<Vec<WorkspaceConfig>, AppError> {
16        WorkspaceStore::list()
17    }
18
19    /// Load a specific workspace by root path.
20    pub fn load(root: &Path) -> Result<WorkspaceConfig, AppError> {
21        WorkspaceStore::load(root)
22    }
23
24    /// Save a workspace config (create or update).
25    pub fn save(workspace: &WorkspaceConfig) -> Result<(), AppError> {
26        WorkspaceStore::save(workspace)
27    }
28
29    /// Delete a workspace by root path.
30    pub fn delete(root: &Path) -> Result<(), AppError> {
31        WorkspaceStore::delete(root)
32    }
33
34    /// Returns the `.git-same/` directory for a workspace root.
35    pub fn dot_dir(root: &Path) -> PathBuf {
36        WorkspaceStore::dot_dir(root)
37    }
38
39    /// Returns the cache file path for a workspace root.
40    pub fn cache_path(root: &Path) -> PathBuf {
41        WorkspaceStore::cache_path(root)
42    }
43
44    /// Returns the sync history file path for a workspace root.
45    pub fn sync_history_path(root: &Path) -> PathBuf {
46        WorkspaceStore::sync_history_path(root)
47    }
48
49    /// Walk up from `start` to find the nearest `.git-same/config.toml`.
50    pub fn detect_from_cwd(start: &Path) -> Option<PathBuf> {
51        WorkspacePolicy::detect_from_cwd(start)
52    }
53
54    /// Resolve which workspace to use.
55    pub fn resolve(
56        name: Option<&str>,
57        config: &super::parser::Config,
58    ) -> Result<WorkspaceConfig, AppError> {
59        WorkspacePolicy::resolve(name, config)
60    }
61
62    /// Resolve from an already-loaded list of workspaces (no filesystem access).
63    pub fn resolve_from_list(
64        workspaces: Vec<WorkspaceConfig>,
65    ) -> Result<WorkspaceConfig, AppError> {
66        WorkspacePolicy::resolve_from_list(workspaces)
67    }
68}
69
70#[cfg(test)]
71#[path = "workspace_manager_tests.rs"]
72mod tests;