mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Data Sets as Files: list skipped sets only when a set was left out
An export without a missing image keeps its old result shape.
This commit is contained in:
1 parent
5409efbd67
commit
9183e68b3a
3 files changed
+12
-7
No files matched your search
@@ -345,9 +345,10 @@ impl Headless {
|
||||
let mut result = exported(dir, written, &mut outputs)?;
|
||||
if let Some(report) = report {
|
||||
let full = report.json(Vec::new());
|
||||
result["skipped"] = full["skipped"].clone();
|
||||
if let Some(stopped) = full.get("stopped") {
|
||||
result["stopped"] = stopped.clone();
|
||||
for key in ["skipped", "stopped"] {
|
||||
if let Some(value) = full.get(key) {
|
||||
result[key] = value.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(result)
|
||||
|
||||
@@ -465,7 +465,7 @@ fn split_csv(line: &str, delim: u8) -> Vec<String> {
|
||||
}
|
||||
|
||||
/// Apply each data set in turn and export the flattened document, restoring the original after.
|
||||
/// `{dir, format?("png"), dataSets?[names], missingImage?, start?}` → `{files:[…],count,skipped,stopped?}`.
|
||||
/// `{dir, format?("png"), dataSets?[names], missingImage?, start?}` → `{files:[…],count,skipped?,stopped?}`.
|
||||
fn export_as_files(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let dir = p.get("dir").and_then(Value::as_str).ok_or_else(|| bad("file.export.dataSetsAsFiles", "need `dir`"))?.to_string();
|
||||
// The directory appears only once the batch has been planned, as it always did, so a batch
|
||||
@@ -518,7 +518,11 @@ impl DataSetsExportReport {
|
||||
/// The command's result, with `files` as the caller names them (joined to its folder).
|
||||
pub fn json(&self, files: Vec<String>) -> Value {
|
||||
let count = files.len();
|
||||
let mut out = json!({"files": files, "count": count, "skipped": self.skipped});
|
||||
let mut out = json!({"files": files, "count": count});
|
||||
// Listed only when a set was left out, so an export without a missing image reads as before.
|
||||
if !self.skipped.is_empty() {
|
||||
out["skipped"] = json!(self.skipped);
|
||||
}
|
||||
if let Some(stop) = &self.stopped {
|
||||
out["stopped"] = json!({"name": stop.name, "index": stop.index, "remaining": stop.remaining, "error": stop.error});
|
||||
}
|
||||
@@ -693,7 +697,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"file.export.dataSetsAsFiles",
|
||||
"Data Sets as Files…",
|
||||
&["File", "Export"],
|
||||
"{dir, format?:png, dataSets?[names], naming?:\"{name}|{index}|{document}\", missingImage?:error|skip|stop, start?:n} → {files,count,skipped,stopped?:{name,index,remaining,error}}: apply each data set and export the flattened document; colliding filenames are rejected before writing (include {index} to disambiguate). A set whose Pixel Replacement image does not exist ends the export with an error (missingImage error, the default), is left out and listed in `skipped` (skip), or ends the export without an error, named in `stopped` (stop); `start` resumes at that 0-based set, keeping {index}",
|
||||
"{dir, format?:png, dataSets?[names], naming?:\"{name}|{index}|{document}\", missingImage?:error|skip|stop, start?:n} → {files,count,skipped?,stopped?:{name,index,remaining,error}}: apply each data set and export the flattened document; colliding filenames are rejected before writing (include {index} to disambiguate). A set whose Pixel Replacement image does not exist ends the export with an error (missingImage error, the default), is left out and listed in `skipped` (skip), or ends the export without an error, named in `stopped` (stop); `start` resumes at that 0-based set, keeping {index}",
|
||||
has_data_sets,
|
||||
|s, p| export_as_files(s, p)
|
||||
),
|
||||
|
||||
@@ -167,7 +167,7 @@ fn the_command_reports_skipped_and_stopped_sets_without_a_prompt() {
|
||||
assert_eq!(r["stopped"]["index"], json!(1));
|
||||
assert_eq!(r["stopped"]["remaining"], json!(1));
|
||||
assert!(r["stopped"]["error"].as_str().unwrap().starts_with(photocraft_engine::DATA_SET_FILE_MISSING));
|
||||
assert_eq!(r["skipped"], json!([]));
|
||||
assert!(r.get("skipped").is_none(), "nothing was skipped: {r}");
|
||||
assert_eq!(files(&dir.join("stop")), ["001.png"]);
|
||||
|
||||
// `start` resumes after the stop and keeps the numbering of the whole batch.
|
||||
|
||||
Reference in new issue
Block a user