Skip to content

Commit

Permalink
fix: Use canonical path when calling print_markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Oct 20, 2024
1 parent a0176e1 commit f1ac222
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions crates/omnix-hack/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<FlakeUrl>::into(dir);
let dir = dir.canonicalize()?;
let here_flake: FlakeUrl = Into::<FlakeUrl>::into(dir.as_ref());
let cfg = HackConfig::from_flake(&here_flake).await?;

// TODO: cachix check
Expand All @@ -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(())
}
6 changes: 3 additions & 3 deletions crates/omnix-init/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
10 changes: 7 additions & 3 deletions crates/omnix-init/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
// Recursively copy the self.template.path to the output directory
omnix_common::fs::copy_dir_all(&self.template.path, out_dir)
.await
Expand All @@ -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
Expand Down

0 comments on commit f1ac222

Please sign in to comment.