diff --git a/apps/designcraft-cli/src/main.rs b/apps/designcraft-cli/src/main.rs index a9839fcd3..44948d54b 100644 --- a/apps/designcraft-cli/src/main.rs +++ b/apps/designcraft-cli/src/main.rs @@ -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()); diff --git a/apps/designcraft-cli/tests/it/cli.rs b/apps/designcraft-cli/tests/it/cli.rs index 861cb514f..0b03ecd5d 100644 --- a/apps/designcraft-cli/tests/it/cli.rs +++ b/apps/designcraft-cli/tests/it/cli.rs @@ -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]