use std::fs;
use std::io;
use std::path::PathBuf;
use super::default_config_path::default_config_path;
use super::theme_config::ThemeConfig;
pub fn save_theme(theme_name: &str, config_path: Option<PathBuf>) -> io::Result<()> {
let path = config_path.or_else(default_config_path).ok_or_else(|| {
io::Error::new(
io::ErrorKind::NotFound,
"Could not determine config directory",
)
})?;
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)?;
}
let config = ThemeConfig {
theme_name: theme_name.to_string(),
};
let json = serde_json::to_string_pretty(&config)
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, format!("JSON error: {}", e)))?;
fs::write(&path, json)?;
Ok(())
}