Merge outside PR #542: Fix CLI export destination precedence

This commit is contained in:
Tanish Manku committed 2026-11-24 15:13:47 -07:00
commit b365ebd3df
1 file changed
+22 -1
+22 -1
View File
@@ -472,7 +472,7 @@ fn export(a: &Args, src: Option<&str>) -> Result<String, String> {
return Err(format!("no export format '{id}' (formats: {}; exporter plug-ins load with --plugins <folder>)", ids.join(", ")));
};
let (cmd, target, plugin) = (f["command"].as_str().unwrap_or(""), f["target"].as_str().unwrap_or("path"), f["plugin"] == true);
let mut p = json!({ target: out });
let mut p = json!({});
let options: Option<Value> = a.flag("options").map(|t| serde_json::from_str(t).map_err(|e| format!("--options is not JSON: {e}"))).transpose()?;
if plugin {
p["format"] = json!(id);
@@ -486,6 +486,7 @@ fn export(a: &Args, src: Option<&str>) -> Result<String, String> {
} else if options.is_some() {
return Err("--options must be a JSON object".into());
}
p[target] = json!(out);
if matches!(id, "png" | "svg") {
if let Some(f) = one_based(a, "frame")? {
p["frame"] = json!(f);
@@ -1125,6 +1126,26 @@ pub(crate) mod tests {
let _ = std::fs::remove_dir_all(&dir);
}
#[test]
fn export_prefers_out_over_a_destination_in_options() {
use anicraft_engine::vfs;
vfs::use_memory();
let export = |format: &str, out: &str, options: &str| {
let argv = ["export", "--sample", "--format", format, "--out", out, "--options", options].map(str::to_string);
serde_json::from_str::<Value>(&run(&argv).unwrap()).unwrap()
};
let written_paths = || vfs::take_written().into_iter().map(|(path, _)| path).collect::<Vec<_>>();
let svg = export("svg", "chosen.svg", r#"{"path":"preset.svg","frame":2}"#);
assert_eq!(svg["frame"], 2);
assert_eq!(written_paths(), [PathBuf::from("chosen.svg")]);
let sequence = export("png-sequence", "chosen-frames", r#"{"dir":"preset-frames","from":0,"to":0,"scale":0.05}"#);
assert_eq!(sequence["frames"], 1);
assert_eq!(written_paths(), [PathBuf::from("chosen-frames").join("frame_00001.png")]);
}
#[test]
fn run_takes_a_saved_command_file() {
let dir = std::env::temp_dir().join(format!("anicraft-cli-macro-{}", std::process::id()));