1use serde::{Deserialize, Serialize};
2use std::path::PathBuf;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct ResolverConfig {
10 #[serde(default = "default_host")]
13 pub default_host: String,
14
15 #[serde(default, skip_serializing_if = "Option::is_none")]
18 pub cache_dir: Option<PathBuf>,
19
20 #[serde(default)]
22 pub include_dev: bool,
23
24 #[serde(default)]
28 pub additional_hosts: Vec<String>,
29}
30
31impl Default for ResolverConfig {
32 fn default() -> Self {
33 Self {
34 default_host: default_host(),
35 cache_dir: None,
36 include_dev: false,
37 additional_hosts: Vec::new(),
38 }
39 }
40}
41
42fn default_host() -> String {
43 "github:pleme-io".to_string()
44}
45
46impl ResolverConfig {
47 pub fn load_or_default() -> Self {
49 let Some(base) = dirs::config_dir() else {
50 return Self::default();
51 };
52 let path = base.join("caixa").join("config.yaml");
53 match std::fs::read_to_string(&path) {
54 Ok(src) => serde_yaml::from_str(&src).unwrap_or_default(),
55 Err(_) => Self::default(),
56 }
57 }
58}