Downloading prototype works

This commit is contained in:
2024-11-19 14:35:33 +02:00
parent b29caa58b4
commit fda77f6981
35 changed files with 1764 additions and 1257 deletions

81
xmpd-cliargs/src/lib.rs Normal file
View File

@@ -0,0 +1,81 @@
use std::{path::PathBuf, str::FromStr, sync::Arc};
use camino::Utf8PathBuf;
use clap::Parser;
lazy_static::lazy_static!(
pub static ref CLIARGS: Arc<CliArgs> = Arc::new(CliArgs::parse());
);
#[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) -> Utf8PathBuf {
self.cache.clone()
}
}
#[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!()
}