feat: I dunno why
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-05-04 20:13:38 +02:00
parent 1d1ac49d0b
commit bf7a7db868
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394

View File

@ -3,6 +3,7 @@ use std::fs::{create_dir_all, read, read_dir};
use std::io::Write;
use std::path::PathBuf;
use anyhow::Context;
use clap::{ArgMatches, Command};
use walkdir::WalkDir;
@ -178,8 +179,16 @@ pub fn execute_init(exe_submatch: &ArgMatches, _cli: CuddleCli) -> anyhow::Resul
}
tracing::info!("writing to: {}", new_path.display());
let new_content =
replace_with_variables(&std::fs::read_to_string(entry_path)?, &template)?;
let old_content = match std::fs::read_to_string(entry_path) {
Ok(e) => e,
Err(e) => {
tracing::debug!("found invalid file possibly with invalid utf8: {}", e);
std::fs::copy(entry_path, new_path).context("failed to write file")?;
continue;
}
};
let new_content = replace_with_variables(&old_content, &template)?;
std::fs::write(new_path, new_content.as_bytes())?;
}