use std::path::PathBuf;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(default)]
pub struct SyncConfig {
pub repo_url: String,
pub local_path: PathBuf,
pub providers: Vec<String>,
pub shallow_clone: bool,
pub branch: String,
pub watch_interval_secs: u64,
}
impl Default for SyncConfig {
fn default() -> Self {
Self {
repo_url: String::new(),
local_path: default_sync_path(),
providers: Vec::new(),
shallow_clone: true,
branch: "main".to_string(),
watch_interval_secs: 60,
}
}
}
fn default_sync_path() -> PathBuf {
dirs::data_local_dir()
.unwrap_or_else(|| PathBuf::from("/tmp"))
.join("sync-auth")
.join("repo")
}
impl SyncConfig {
pub fn load_from_file(path: &std::path::Path) -> Result<Self, crate::SyncError> {
if !path.exists() {
return Err(crate::SyncError::Config(format!(
"config file not found: {}",
path.display()
)));
}
let content =
std::fs::read_to_string(path).map_err(|e| crate::SyncError::Config(e.to_string()))?;
toml::from_str(&content)
.map_err(|e| crate::SyncError::Config(format!("invalid config TOML: {e}")))
}
pub fn default_config_path() -> PathBuf {
dirs::config_dir()
.unwrap_or_else(|| PathBuf::from("~/.config"))
.join("sync-auth")
.join("config.toml")
}
}