From 4842000c3194d7bbd006b6e59fd2e4ff9a3af5e0 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Mon, 23 Mar 2026 02:47:58 +0100 Subject: [PATCH] feat(cli): add --cell-size flag, route png through build_png --- crates/bin/src/cli.rs | 20 ++++++++++++++++---- crates/exporters/src/lib.rs | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/bin/src/cli.rs b/crates/bin/src/cli.rs index 9f9f37a..5e08125 100644 --- a/crates/bin/src/cli.rs +++ b/crates/bin/src/cli.rs @@ -65,6 +65,10 @@ struct Cli { /// Width in blocks inserted for a space character #[arg(long, default_value_t = 4)] word_spacing: u32, + + /// Cell size in pixels for PNG export (8-64) + #[arg(long, default_value_t = 16, value_parser = clap::value_parser!(u32).range(8..=64))] + cell_size: u32, } fn palettes_dir() -> PathBuf { @@ -160,12 +164,20 @@ pub fn run() -> anyhow::Result<()> { .filter(|&name| seen.insert(name)) .collect(); - // Build and validate in one pass + // Build and validate in one pass; route "png" through build_png to honour --cell-size let exporters_to_run = format_names .iter() - .map(|&name| -> anyhow::Result<_> { - exporters::build(name, &palette) - .ok_or_else(|| anyhow::anyhow!("unknown format '{}'. Available: {}", name, all_names.join(", "))) + .map(|&name| -> anyhow::Result> { + if name == "png" { + Ok(exporters::build_png(&palette, cli.cell_size)) + } else { + exporters::build(name, &palette) + .ok_or_else(|| anyhow::anyhow!( + "unknown format '{}'. Available: {}", + name, + all_names.join(", ") + )) + } }) .collect::>>()?; diff --git a/crates/exporters/src/lib.rs b/crates/exporters/src/lib.rs index 1588f27..5b6a3a5 100644 --- a/crates/exporters/src/lib.rs +++ b/crates/exporters/src/lib.rs @@ -13,6 +13,7 @@ type ExporterFactory = fn(&BlockPalette) -> Box; const REGISTRY: &[(&str, ExporterFactory)] = &[ ("mcfunction", |p| Box::new(McFunctionExporter::new(p))), ("litematica", |p| Box::new(LitematicaExporter::new(p))), + // cell_size=16 default; CLI uses build_png() to honour --cell-size ("png", |p| Box::new(PngExporter::new(p, 16))), ];