use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResolverConfig {
#[serde(default = "default_host")]
pub default_host: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cache_dir: Option<PathBuf>,
#[serde(default)]
pub include_dev: bool,
#[serde(default)]
pub additional_hosts: Vec<String>,
}
impl Default for ResolverConfig {
fn default() -> Self {
Self {
default_host: default_host(),
cache_dir: None,
include_dev: false,
additional_hosts: Vec::new(),
}
}
}
fn default_host() -> String {
"github:pleme-io".to_string()
}
impl ResolverConfig {
pub fn load_or_default() -> Self {
let Some(base) = dirs::config_dir() else {
return Self::default();
};
let path = base.join("caixa").join("config.yaml");
match std::fs::read_to_string(&path) {
Ok(src) => serde_yaml::from_str(&src).unwrap_or_default(),
Err(_) => Self::default(),
}
}
}