diff --git a/README.md b/README.md index cbd141a..40701c3 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Optional: 3. Remove duplicates by applying an undo/redo JSON file ```sh - orcli transform "duplicates" "https://git.io/fj5hF" + orcli transform "duplicates" "https://git.io/fj5ju" ``` 4. Export data from OpenRefine project to tab-separated-values (TSV) file `duplicates.tsv` diff --git a/orcli b/orcli index 8287b81..6495723 100755 --- a/orcli +++ b/orcli @@ -887,10 +887,17 @@ orcli_transform_command() { # support multiple files for i in "${!files[@]}"; do # read each operation into one line - mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}") + if json="$(jq -c '.[]' "${files[$i]}")"; then + mapfile -t jsonlines <<<"$json" + else + error "parsing ${files[$i]} failed!" + fi for line in "${jsonlines[@]}"; do # parse one line/operation into array declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" + if [[ ! ${data[op]} ]]; then + error "parsing ${files[$i]} failed!" + fi # map operation names to command endpoints # https://github.com/OpenRefine/OpenRefine/blob/master/main/webapp/modules/core/MOD-INF/controller.js com="${data[op]#core/}" diff --git a/src/transform_command.sh b/src/transform_command.sh index fde2047..8da451a 100644 --- a/src/transform_command.sh +++ b/src/transform_command.sh @@ -29,10 +29,17 @@ done # support multiple files for i in "${!files[@]}"; do # read each operation into one line - mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}") + if json="$(jq -c '.[]' "${files[$i]}")"; then + mapfile -t jsonlines <<<"$json" + else + error "parsing ${files[$i]} failed!" + fi for line in "${jsonlines[@]}"; do # parse one line/operation into array declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" + if [[ ! ${data[op]} ]]; then + error "parsing ${files[$i]} failed!" + fi # map operation names to command endpoints # https://github.com/OpenRefine/OpenRefine/blob/master/main/webapp/modules/core/MOD-INF/controller.js com="${data[op]#core/}"