fix(cli): build exporters once, clarify --format all doc
This commit is contained in:
@@ -34,7 +34,7 @@ struct Cli {
|
||||
#[arg(short, long, default_value = "output")]
|
||||
out: PathBuf,
|
||||
|
||||
/// Output format(s): mcfunction, litematica, or all (repeatable)
|
||||
/// Output format(s): mcfunction, litematica, all (overrides others), or repeatable values
|
||||
#[arg(long, value_name = "FORMAT")]
|
||||
format: Vec<String>,
|
||||
|
||||
@@ -160,15 +160,16 @@ pub fn run() -> anyhow::Result<()> {
|
||||
.filter(|&name| seen.insert(name))
|
||||
.collect();
|
||||
|
||||
// Pre-validate all names before writing anything
|
||||
for name in &format_names {
|
||||
if exporters::build(name, &palette).is_none() {
|
||||
anyhow::bail!("unknown format '{}'. Available: {}", name, all_names.join(", "));
|
||||
}
|
||||
}
|
||||
// Build and validate in one pass
|
||||
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(", ")))
|
||||
})
|
||||
.collect::<anyhow::Result<Vec<_>>>()?;
|
||||
|
||||
for name in format_names {
|
||||
let exporter = exporters::build(name, &palette).unwrap(); // safe: pre-validated
|
||||
for (name, exporter) in format_names.iter().zip(exporters_to_run) {
|
||||
let output_bytes = exporter.export(&grid)?;
|
||||
let mut out_path = cli.out.clone();
|
||||
out_path.set_extension(exporter.file_extension());
|
||||
|
||||
Reference in New Issue
Block a user