diff --git a/crates/omnix-hack/src/core.rs b/crates/omnix-hack/src/core.rs index 545df794..e4e63eda 100644 --- a/crates/omnix-hack/src/core.rs +++ b/crates/omnix-hack/src/core.rs @@ -6,7 +6,8 @@ use omnix_common::markdown::print_markdown; use crate::config::HackConfig; pub async fn hack_on(dir: &Path) -> anyhow::Result<()> { - let here_flake: FlakeUrl = Into::::into(dir); + let dir = dir.canonicalize()?; + let here_flake: FlakeUrl = Into::::into(dir.as_ref()); let cfg = HackConfig::from_flake(&here_flake).await?; // TODO: cachix check @@ -20,7 +21,7 @@ pub async fn hack_on(dir: &Path) -> anyhow::Result<()> { } eprintln!(); - print_markdown(dir, &cfg.readme.get_markdown()).await?; + print_markdown(&dir, &cfg.readme.get_markdown()).await?; Ok(()) } diff --git a/crates/omnix-init/src/core.rs b/crates/omnix-init/src/core.rs index b5828194..9989ef8a 100644 --- a/crates/omnix-init/src/core.rs +++ b/crates/omnix-init/src/core.rs @@ -105,21 +105,21 @@ pub async fn run( async fn initialize_template<'a>(path: &Path, template: &FlakeTemplate<'a>) -> anyhow::Result<()> { tracing::info!("Initializing template at {}", path.display()); - template + let path = template .template .scaffold_at(path) .await .with_context(|| "Unable to scaffold")?; eprintln!(); print_markdown( - path, + &path, &format!("## 🥳 Initialized template at `{}`", path.display()), ) .await?; if let Some(welcome_text) = template.template.template.welcome_text.as_ref() { eprintln!(); - print_markdown(path, welcome_text).await?; + print_markdown(&path, welcome_text).await?; } Ok(()) diff --git a/crates/omnix-init/src/template.rs b/crates/omnix-init/src/template.rs index f45be497..1fd988a4 100644 --- a/crates/omnix-init/src/template.rs +++ b/crates/omnix-init/src/template.rs @@ -29,8 +29,10 @@ pub struct NixTemplate { } impl Template { - // Scaffold the [Template] at the given path. - pub async fn scaffold_at(&self, out_dir: &Path) -> anyhow::Result<()> { + /// Scaffold the [Template] at the given path. + // + /// Returns the canonicalized path of the output directory + pub async fn scaffold_at(&self, out_dir: &Path) -> anyhow::Result { // Recursively copy the self.template.path to the output directory omnix_common::fs::copy_dir_all(&self.template.path, out_dir) .await @@ -39,7 +41,9 @@ impl Template { // Do param replacements self.apply_actions(out_dir).await?; - Ok(()) + out_dir + .canonicalize() + .with_context(|| "Unable to canonicalize path") } /// Set 'default' fields of prompts to the user-defined values