use crate::cli::OutputFormat;
use crate::error::CliError;
use crate::templates::{
RenderContext, canonical_templates, render_template, template_to_output_path,
};
pub fn run(output: &OutputFormat) -> Result<(), CliError> {
let ctx = RenderContext::default();
let mut entries: Vec<(&str, &str, String, usize)> = Vec::new();
for &template_path in canonical_templates() {
let rendered = render_template(template_path, &ctx)
.ok_or_else(|| CliError::Generic(format!("template not found: {template_path}")))?;
let hash = crate::hash::sha256_hex(&rendered);
let size = rendered.len();
let output_path = template_to_output_path(template_path);
entries.push((template_path, output_path, hash, size));
}
match output {
OutputFormat::Json => {
let json_entries: Vec<_> = entries
.iter()
.map(|(tpl, out, hash, size)| {
serde_json::json!({
"template": tpl,
"output_path": out,
"sha256": hash,
"size_bytes": size,
})
})
.collect();
println!(
"{}",
serde_json::to_string_pretty(&json_entries).unwrap_or_default()
);
}
_ => {
println!("{:<35} {:<35} SHA-256 (16 chars)", "Template", "Output");
println!("{}", "-".repeat(90));
for (tpl, out, hash, size) in &entries {
println!("{:<35} {:<35} {}... ({size}B)", tpl, out, &hash[..16]);
}
}
}
Ok(())
}