use std::{path::PathBuf, str::FromStr}; #[derive(Debug, clap::Parser)] pub struct CliArgs { /// Manifest path #[arg(long, short, default_value_t=get_default_manifest_path())] manifest: camino::Utf8PathBuf, /// settings file path #[arg(long, short, default_value_t=get_default_settings_path())] settings: camino::Utf8PathBuf, /// Cache dir path #[arg(long, short, default_value_t=get_default_cache_path())] cache: camino::Utf8PathBuf, /// Debug mode #[arg(long, short)] pub debug: bool, } impl CliArgs { pub fn manifest_path(&self) -> PathBuf { self.manifest.clone().into_std_path_buf() } pub fn settings_path(&self) -> PathBuf { self.settings.clone().into_std_path_buf() } pub fn cache_path(&self) -> PathBuf { self.cache.clone().into_std_path_buf() } } #[allow(irrefutable_let_patterns)] // Broken? fn get_default_settings_path() -> camino::Utf8PathBuf { if let Ok(p) = std::env::var("XMPD_SETTINGS_PATH") { if let Ok(p) = camino::Utf8PathBuf::from_str(&p) { return p; } } if let Some(mut p) = dirs::config_dir() { p.push("xmpd"); p.push("config.toml"); return camino::Utf8PathBuf::from_path_buf(p).expect("Invalid os path"); } unreachable!() } #[allow(irrefutable_let_patterns)] // Broken? fn get_default_manifest_path() -> camino::Utf8PathBuf { if let Ok(p) = std::env::var("XMPD_MANIFEST_PATH") { if let Ok(p) = camino::Utf8PathBuf::from_str(&p) { return p; } } if let Some(mut p) = dirs::config_dir() { p.push("xmpd"); p.push("manifest.json"); return camino::Utf8PathBuf::from_path_buf(p).expect("Invalid os path"); } unreachable!() } #[allow(irrefutable_let_patterns)] // Broken? fn get_default_cache_path() -> camino::Utf8PathBuf { if let Ok(p) = std::env::var("XMPD_CACHE_PATH") { if let Ok(p) = camino::Utf8PathBuf::from_str(&p) { return p; } } if let Some(mut p) = dirs::cache_dir() { p.push("xmpd"); return camino::Utf8PathBuf::from_path_buf(p).expect("Invalid os path"); } unreachable!() }