From 763c7107700e67156ae24b85e953d7ebea016c25 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Wed, 27 Jul 2022 20:52:52 -0700 Subject: [PATCH] fix(cli): smarter windows path resolution This commit improves Windows path resolution so that when people run the ahk-asc command with "applications.yaml" as an argument, without having ".\" prepended, the command will still succeed as expected. fix #192 --- komorebic/src/main.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 7b93d779..cd177841 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -1293,15 +1293,18 @@ fn resolve_windows_path(raw_path: &str) -> Result { .parent() .ok_or_else(|| anyhow!("cannot parse directory"))?; - let file = full_path - .components() - .last() - .ok_or_else(|| anyhow!("cannot parse filename"))?; + Ok(if parent.is_dir() { + let file = full_path + .components() + .last() + .ok_or_else(|| anyhow!("cannot parse filename"))?; - let mut canonicalized = std::fs::canonicalize(parent)?; - canonicalized.push(file); - - Ok(canonicalized) + let mut canonicalized = std::fs::canonicalize(parent)?; + canonicalized.push(file); + canonicalized + } else { + full_path + }) } fn show_window(hwnd: HWND, command: SHOW_WINDOW_CMD) {