ccsync_core/
config.rs

1//! Configuration file parsing, merging, and pattern matching
2//!
3//! This module handles:
4//! - Config file discovery from multiple locations
5//! - TOML parsing with serde
6//! - Config merging with precedence rules
7//! - Gitignore-style pattern matching
8//! - Direction and type-specific rules
9//! - Validation and error reporting
10
11mod discovery;
12mod merge;
13mod patterns;
14mod types;
15mod validation;
16
17#[cfg(test)]
18mod integration_tests;
19
20pub use discovery::ConfigDiscovery;
21pub use merge::ConfigMerger;
22#[allow(unused_imports)] // Will be used by sync engine (Task 6)
23pub use patterns::PatternMatcher;
24pub use types::{Config, SyncDirection};
25pub use validation::ConfigValidator;
26
27use crate::error::Result;
28
29/// Configuration manager that coordinates discovery, parsing, merging, and validation
30pub struct ConfigManager;
31
32impl ConfigManager {
33    /// Create a new configuration manager
34    #[must_use]
35    pub const fn new() -> Self {
36        Self
37    }
38
39    /// Load and merge configuration from all sources
40    ///
41    /// # Errors
42    ///
43    /// Returns an error if config files are invalid or cannot be read.
44    pub fn load(cli_config_path: Option<&std::path::Path>) -> Result<Config> {
45        // Discover all config files
46        let config_files = ConfigDiscovery::discover(cli_config_path)?;
47
48        // Parse and merge configs
49        let merged = ConfigMerger::merge(&config_files)?;
50
51        // Validate the final configuration
52        ConfigValidator::validate(&merged)?;
53
54        Ok(merged)
55    }
56}
57
58impl Default for ConfigManager {
59    fn default() -> Self {
60        Self::new()
61    }
62}
63
64#[cfg(test)]
65mod tests {
66    use super::*;
67
68    #[test]
69    fn test_config_manager_creation() {
70        let _manager = ConfigManager::new();
71        let _default_manager = ConfigManager::default();
72        // Successfully created without panic
73    }
74}