feat: without remove dir all assertion
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
85cc1d46db
commit
ede55b975b
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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"),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user