use anyhow::Result;
use clap::Args;
use std::path::PathBuf;
use dkp_core::Pack;
use dkp_gen_core::render_handbook_formats;
use crate::cli::CmdCtx;
#[derive(Args, Debug)]
pub struct RenderHandbookArgs {
pub pack: PathBuf,
}
pub async fn run(args: RenderHandbookArgs, _cli: &CmdCtx) -> Result<()> {
let pack = Pack::open(&args.pack)?;
let human_dir = pack.root.join("human");
let md_path = human_dir.join("handbook.md");
let markdown = std::fs::read_to_string(&md_path).map_err(|_| {
anyhow::anyhow!(
"human/handbook.md not found at {} — nothing to render",
md_path.display()
)
})?;
let report = render_handbook_formats(&markdown, &human_dir)?;
for w in &report.warnings {
eprintln!(" ⚠ {w}");
}
if report.pdf_written {
println!(" Written: {}", human_dir.join("handbook.pdf").display());
}
if report.epub_written {
println!(" Written: {}", human_dir.join("handbook.epub").display());
}
Ok(())
}