Merge pull request #74 from opencultureconsulting:felixlohmeier/transform-5

transform: improve error handling
This commit is contained in:
Felix Lohmeier 2022-11-13 23:14:27 +01:00 committed by GitHub
commit 1c22ceca01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View File

@ -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`

9
orcli
View File

@ -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/}"

View File

@ -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/}"