feat(cli): add --format flag for universal exporter selection
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use clap::Parser;
|
||||
use exporters::McFunctionExporter;
|
||||
use lib::{BlockPalette, OutlineMode, StructureExporter, TextBuilder, TtfFont};
|
||||
use exporters;
|
||||
use lib::{BlockPalette, OutlineMode, TextBuilder, TtfFont};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
@@ -35,6 +35,10 @@ struct Cli {
|
||||
#[arg(short, long, default_value = "output")]
|
||||
out: PathBuf,
|
||||
|
||||
/// Output format(s): mcfunction, litematica, or all (repeatable)
|
||||
#[arg(long, value_name = "FORMAT")]
|
||||
format: Vec<String>,
|
||||
|
||||
/// Height of the text in blocks
|
||||
#[arg(long, default_value_t = 16.0)]
|
||||
size: f32,
|
||||
@@ -140,14 +144,24 @@ pub fn run() -> anyhow::Result<()> {
|
||||
grid.depth
|
||||
);
|
||||
|
||||
let exporter = McFunctionExporter::new(&palette);
|
||||
let output_bytes = exporter.export(&grid)?;
|
||||
let format_names: Vec<&str> = if cli.format.is_empty() {
|
||||
vec!["mcfunction"]
|
||||
} else if cli.format.iter().any(|f| f == "all") {
|
||||
exporters::available_names()
|
||||
} else {
|
||||
cli.format.iter().map(String::as_str).collect()
|
||||
};
|
||||
|
||||
let mut out_path = cli.out.clone();
|
||||
out_path.set_extension(exporter.file_extension());
|
||||
for name in format_names {
|
||||
let exporter = exporters::build(name, &palette)
|
||||
.ok_or_else(|| anyhow::anyhow!("unknown format '{}'. Available: {}", name, exporters::available_names().join(", ")))?;
|
||||
|
||||
fs::write(&out_path, output_bytes)?;
|
||||
tracing::info!("saved to: {:?}", out_path);
|
||||
let output_bytes = exporter.export(&grid)?;
|
||||
let mut out_path = cli.out.clone();
|
||||
out_path.set_extension(exporter.file_extension());
|
||||
fs::write(&out_path, &output_bytes)?;
|
||||
tracing::info!("saved {} to: {:?}", name, out_path);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user