use std::path::PathBuf;
use anyhow::Context;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct SearchPath {
pub path: String,
pub depth: u32,
}
#[derive(Debug, Deserialize)]
pub struct Config {
pub search_paths: Vec<SearchPath>,
}
fn config_path() -> PathBuf {
std::env::var("XDG_CONFIG_HOME")
.map(PathBuf::from)
.unwrap_or_else(|_| {
std::env::var("HOME")
.map(|h| PathBuf::from(h).join(".config"))
.unwrap_or_else(|_| PathBuf::from(".config"))
})
.join("phonto")
.join("config.toml")
}
pub fn load() -> anyhow::Result<Config> {
let path = config_path();
let contents = std::fs::read_to_string(&path)
.with_context(|| format!("failed to read config from {}", path.display()))?;
toml::from_str(&contents).with_context(|| "failed to parse config")
}