From da00f412055f5d427d99a9ad4f4acc166d8afbed Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 4 Aug 2025 10:45:15 +0200 Subject: [PATCH] fix: if path is empty default to `.` --- Cargo.lock | 2 +- crates/noil/src/cli/edit.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d8da452..e9448bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -431,7 +431,7 @@ dependencies = [ [[package]] name = "noil" -version = "0.0.5" +version = "0.1.0" dependencies = [ "ansi_term", "anyhow", diff --git a/crates/noil/src/cli/edit.rs b/crates/noil/src/cli/edit.rs index 18864be..0403817 100644 --- a/crates/noil/src/cli/edit.rs +++ b/crates/noil/src/cli/edit.rs @@ -62,9 +62,10 @@ impl EditCommand { .await .context("create temp file for noil")?; - let output = get_outputs(&self.get_path().await.context("get path")?, true) + let path = &self.get_path().await.context("get path")?; + let output = get_outputs(path, true) .await - .context("get output")?; + .context(format!("get output: {}", path.display()))?; file.write_all(output.as_bytes()) .await .context("write contents for edit")?; @@ -151,10 +152,16 @@ impl EditCommand { } if path.is_file() { - return path + let parent_path = path .parent() .map(|p| p.to_path_buf()) - .ok_or(anyhow::anyhow!("parent doesn't exist for file")); + .ok_or(anyhow::anyhow!("parent doesn't exist for file"))?; + + if parent_path.display().to_string() == "" { + return Ok(PathBuf::from(".")); + } + + return Ok(parent_path); } Ok(path.clone())