use std::{
fs,
path::{Path, PathBuf},
};
use crate::normalize_lexical;
use crate::config::ConfigResult;
pub(crate) fn write_template(path: &Path, content: &str) -> ConfigResult<()> {
if let Some(parent) = path
.parent()
.filter(|parent| !parent.as_os_str().is_empty())
{
fs::create_dir_all(parent)?;
}
fs::write(path, content)?;
Ok(())
}
pub(crate) fn resolve_config_template_output(output: Option<PathBuf>) -> ConfigResult<PathBuf> {
let current_dir = std::env::current_dir()?;
let output = output.unwrap_or_else(|| PathBuf::from("config.example.yaml"));
let output = if output.is_absolute() {
output
} else {
current_dir.join(output)
};
Ok(normalize_lexical(output))
}