1use std::path::PathBuf;
4
5#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
7#[serde(default)]
8pub struct SyncConfig {
9 pub repo_url: String,
11
12 pub local_path: PathBuf,
14
15 pub providers: Vec<String>,
18
19 pub shallow_clone: bool,
21
22 pub branch: String,
24
25 pub watch_interval_secs: u64,
27}
28
29impl Default for SyncConfig {
30 fn default() -> Self {
31 Self {
32 repo_url: String::new(),
33 local_path: default_sync_path(),
34 providers: Vec::new(),
35 shallow_clone: true,
36 branch: "main".to_string(),
37 watch_interval_secs: 60,
38 }
39 }
40}
41
42fn default_sync_path() -> PathBuf {
44 dirs::data_local_dir()
45 .unwrap_or_else(|| PathBuf::from("/tmp"))
46 .join("sync-auth")
47 .join("repo")
48}
49
50impl SyncConfig {
51 pub fn load_from_file(path: &std::path::Path) -> Result<Self, crate::SyncError> {
53 if !path.exists() {
54 return Err(crate::SyncError::Config(format!(
55 "config file not found: {}",
56 path.display()
57 )));
58 }
59 let content =
60 std::fs::read_to_string(path).map_err(|e| crate::SyncError::Config(e.to_string()))?;
61 toml::from_str(&content)
62 .map_err(|e| crate::SyncError::Config(format!("invalid config TOML: {e}")))
63 }
64
65 pub fn default_config_path() -> PathBuf {
67 dirs::config_dir()
68 .unwrap_or_else(|| PathBuf::from("~/.config"))
69 .join("sync-auth")
70 .join("config.toml")
71 }
72}