diff --git a/cuddle/src/cli/subcommands/folder.rs b/cuddle/src/cli/subcommands/folder.rs index d7cb6fb..7cf080c 100644 --- a/cuddle/src/cli/subcommands/folder.rs +++ b/cuddle/src/cli/subcommands/folder.rs @@ -72,8 +72,8 @@ impl FolderCommand { } pub fn execute(self) -> anyhow::Result<()> { - std::fs::remove_dir_all(&self.destination)?; - std::fs::create_dir_all(&self.destination)?; + let _ = std::fs::remove_dir_all(&self.destination); + std::fs::create_dir_all(&self.destination).context("failed to create directory")?; // Prepare context let mut context = tera::Context::new(); @@ -86,7 +86,7 @@ impl FolderCommand { tera.register_function("filter_by_prefix", filter_by_prefix(self.variables.clone())); for entry in walkdir::WalkDir::new(&self.source) { - let entry = entry?; + let entry = entry.context("entry was not found")?; let entry_path = entry.path(); let rel_path = self .destination @@ -94,12 +94,13 @@ impl FolderCommand { if entry_path.is_file() { // Load source template - let source = std::fs::read_to_string(entry_path)?; + let source = std::fs::read_to_string(entry_path) + .context("failed to read entry into memory")?; let output = tera.render_str(&source, &context)?; if let Some(parent) = rel_path.parent() { - std::fs::create_dir_all(parent)?; + std::fs::create_dir_all(parent).context("failed to create parent dir")?; } // Put template in final destination diff --git a/cuddle/src/cli/subcommands/kustomize.rs b/cuddle/src/cli/subcommands/kustomize.rs index 014182d..f0deb6f 100644 --- a/cuddle/src/cli/subcommands/kustomize.rs +++ b/cuddle/src/cli/subcommands/kustomize.rs @@ -47,7 +47,7 @@ impl KustomizeCommand { pub fn execute(self) -> anyhow::Result<()> { let mut cmd = std::process::Command::new("kubectl"); - std::fs::remove_dir_all(&self.destination)?; + let _ = std::fs::remove_dir_all(&self.destination); std::fs::create_dir_all(&self.destination)?; let cmd = cmd.arg("kustomize").arg(self.kustomize_folder); diff --git a/cuddle/src/cli/subcommands/render.rs b/cuddle/src/cli/subcommands/render.rs index 77a5af7..f3eb156 100644 --- a/cuddle/src/cli/subcommands/render.rs +++ b/cuddle/src/cli/subcommands/render.rs @@ -1,3 +1,4 @@ +use anyhow::Context; use clap::{ArgMatches, Command}; use crate::cli::CuddleCli; @@ -21,7 +22,9 @@ impl RenderCommand { KustomizeCommand::from_matches(sub_matches, cli)?.execute()?; } Some(("folder", sub_matches)) => { - FolderCommand::from_matches(sub_matches, cli)?.execute()?; + FolderCommand::from_matches(sub_matches, cli)? + .execute() + .context("failed to render folder")?; } _ => anyhow::bail!("failed to find match for render"), }