diff --git a/orcli b/orcli index fe993e1..b07d801 100755 --- a/orcli +++ b/orcli @@ -889,9 +889,9 @@ orcli_transform_command() { # read each operation into one line mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}") for line in "${jsonlines[@]}"; do - # parse operation into curl options + # parse one line/operation into array declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" - # map operation name to command + # map operation names to command endpoints com="${data[op]#core/}" if [[ $com == "row-reorder" ]]; then com="reorder-rows"; fi unset "data[op]" @@ -900,17 +900,17 @@ orcli_transform_command() { unset "data[engineConfig]" # drop description unset "data[description]" + # prepare curl options mapfile -t curloptions < <(for K in "${!data[@]}"; do echo "--data" echo "$K=${data[$K]}" done) # get project id and csrf token; post data to it's individual endpoint - set -x - # debug: remove -fs - if ! curl --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)"; then - error "applying ${op} from ${files[$i]} failed!" + if response="$(curl -fs --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)")"; then + log "applied ${com} to ${args[project]}" "Response: $(jq '.historyEntry.description' <<< "$response")" + else + error "applying ${com} from ${files[$i]} to ${args[project]} failed!" fi - set +x unset data done done diff --git a/src/transform_command.sh b/src/transform_command.sh index 927676a..51aa9d6 100644 --- a/src/transform_command.sh +++ b/src/transform_command.sh @@ -31,9 +31,9 @@ for i in "${!files[@]}"; do # read each operation into one line mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}") for line in "${jsonlines[@]}"; do - # parse operation into curl options + # parse one line/operation into array declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))" - # map operation name to command + # map operation names to command endpoints com="${data[op]#core/}" if [[ $com == "row-reorder" ]]; then com="reorder-rows"; fi unset "data[op]" @@ -42,14 +42,16 @@ for i in "${!files[@]}"; do unset "data[engineConfig]" # drop description unset "data[description]" + # prepare curl options mapfile -t curloptions < <(for K in "${!data[@]}"; do echo "--data" echo "$K=${data[$K]}" done) # get project id and csrf token; post data to it's individual endpoint - # debug: remove -fs option temporarily - if ! curl --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)"; then - error "applying ${op} from ${files[$i]} failed!" + if response="$(curl -fs --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${com}$(get_csrf)")"; then + log "applied ${com} to ${args[project]}" "Response: $(jq '.historyEntry.description' <<< "$response")" + else + error "applying ${com} from ${files[$i]} to ${args[project]} failed!" fi unset data done