holodeck_simctl_core/
config_resolver.rs1use std::path::{Path, PathBuf};
2
3#[derive(Debug, Clone)]
6pub struct ConfigResolver {
7 base: PathBuf,
8}
9
10impl ConfigResolver {
11 pub fn live() -> Self {
12 let parent = std::env::var("XDG_CONFIG_HOME")
13 .ok()
14 .filter(|xdg| !xdg.is_empty())
15 .map(|xdg| PathBuf::from(shellexpand::tilde(&xdg).into_owned()))
16 .or_else(|| dirs::home_dir().map(|home| home.join(".config")))
17 .unwrap_or_else(|| PathBuf::from(".config"));
18 Self { base: parent.join("holodeck") }
19 }
20
21 pub fn mock(base: impl Into<PathBuf>) -> Self {
22 Self { base: base.into() }
23 }
24
25 pub fn base(&self) -> &Path {
26 &self.base
27 }
28
29 pub fn file(&self, file_name: &str) -> PathBuf {
30 self.base.join(file_name)
31 }
32}