From b64c0e127d6e6d2283cf2322c3f13e26dacc4b7b Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 9 Feb 2024 16:49:49 -0800 Subject: [PATCH] feat(config): recognize komorebi_config_home for asc path This commit ensures that the KOMOREBI_CONFIG_HOME environment variable is recognized by the komorebic check command and the static config loader when used to specify the location of the applications.yaml file. resolve #660 --- komorebi-core/src/lib.rs | 10 ++++++++++ komorebic/src/main.rs | 9 ++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index 3a7ba4ec..4872ba86 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -319,6 +319,16 @@ pub fn resolve_home_path>(path: P) -> Result { resolved = true; } + std::path::Component::Normal(c) if (c == "$Env:KOMOREBI_CONFIG_HOME") && !resolved => { + let komorebi_config_home = + PathBuf::from(std::env::var("KOMOREBI_CONFIG_HOME").ok().ok_or_else(|| { + anyhow!("there is no KOMOREBI_CONFIG_HOME environment variable set") + })?); + + resolved_path.extend(komorebi_config_home.components()); + resolved = true; + } + _ => resolved_path.push(c), } } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 158dc6e3..e191c297 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -1344,7 +1344,7 @@ fn main() -> Result<()> { if let Ok(config) = &parsed_config { if let Some(asc_path) = config.get("app_specific_configuration_path") { - let normalized_asc_path = asc_path + let mut normalized_asc_path = asc_path .to_string() .replace( "$Env:USERPROFILE", @@ -1353,6 +1353,13 @@ fn main() -> Result<()> { .replace('"', "") .replace('\\', "/"); + if let Ok(komorebi_config_home) = std::env::var("KOMOREBI_CONFIG_HOME") { + normalized_asc_path = normalized_asc_path + .replace("$Env:KOMOREBI_CONFIG_HOME", &komorebi_config_home) + .replace('"', "") + .replace('\\', "/"); + } + if !Path::exists(Path::new(&normalized_asc_path)) { println!("Application specific configuration file path '{normalized_asc_path}' does not exist. Try running 'komorebic fetch-asc'\n"); }