cli: script --export prints the export's warnings, as run does (#2191)

The script command threw away the result of each export, so a PDF with
a drop shadow came out with nothing on stderr, while run --export
printed "warning: 1 object(s) with soft effects ... exported as images".
Each warning an export returns now goes to stderr as "warning: ...".
The JSON report on stdout is unchanged.
This commit is contained in:
JonRC committed 2026-11-03 01:05:17 -03:00
1 parent 74eab18d16
commit 41c59708eb
2 files changed
+35 -1

No files matched your search

+6 -1
View File
@@ -533,7 +533,7 @@ fn script(args: &[String]) -> Result<(), String> {
}
for (kind, out) in &export {
let p = json!({"path": out});
match kind {
let r = match kind {
// PNG / JPEG of the first page.
Export::Image => b.call("app.export", p)?,
Export::Pdf => exec(b, "file.exportPdf", p)?,
@@ -542,6 +542,11 @@ fn script(args: &[String]) -> Result<(), String> {
Export::Pptx => exec(b, "file.exportPptx", p)?,
Export::Command(cmd) => exec(b, cmd, p)?,
};
// What the export itself reports (effects rasterised, transparency flattened…) goes
// to stderr, as `run --export` prints it: the report on stdout covers only the steps.
for w in r["warnings"].as_array().into_iter().flatten() {
eprintln!("warning: {}", w.as_str().unwrap_or_default());
}
}
}
outln!("{}", serde_json::to_string_pretty(&report.to_json()).unwrap_or_default());
+29
View File
@@ -95,6 +95,35 @@ fn export_to_an_unknown_file_type_is_an_error() {
let _ = std::fs::remove_dir_all(&dir);
}
/// `run --export` prints what the PDF export reports, and `script --export` dropped it: the same
/// PDF with a drop shadow came out of a script with nothing on stderr.
#[test]
fn script_export_prints_the_export_warnings_as_run_does() {
let dir = std::env::temp_dir().join(format!("dc-cli-warnings-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
let steps = [
r#"frame.create={"rect": [72, 72, 300, 200]}"#,
r#"object.fill={"ids": ["$0.id"], "swatch": "[Black]"}"#,
r#"object.dropShadow={"ids": ["$0.id"], "on": true, "distance": 8, "size": 6}"#,
];
let script = dir.join("shadow.dcs");
std::fs::write(&script, steps.join("\n")).unwrap();
let pdf = dir.join("shadow.pdf");
let pdf = pdf.to_str().unwrap();
let mut run = vec!["run"];
for step in steps {
run.extend(["--cmd", step]);
}
run.extend(["--export", pdf]);
for args in [run, vec!["script", script.to_str().unwrap(), "--export", pdf]] {
let out = cli().args(&args).output().unwrap();
let err = String::from_utf8_lossy(&out.stderr);
assert!(out.status.success(), "{}: {err}", args[0]);
assert!(err.contains("warning: 1 object(s) with soft effects"), "{}: {err}", args[0]);
}
let _ = std::fs::remove_dir_all(&dir);
}
/// With `--connect` the exports happen in the running app. `--export copy.designcraft` saves a
/// copy there: Save As would make the copy the file the open document saves to from then on.
#[test]