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