feat: without remove dir all assertion
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-01-28 16:54:25 +01:00
parent 85cc1d46db
commit ede55b975b
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
3 changed files with 11 additions and 7 deletions

View File

@ -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

View File

@ -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);

View File

@ -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"),
}