Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
1d1ac49d0b
commit
bf7a7db868
@ -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())?;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user