first try (untested)
This commit is contained in:
parent
26feff650a
commit
cf83aac692
|
@ -1,5 +1,4 @@
|
||||||
# shellcheck shell=bash disable=SC2154
|
# shellcheck shell=bash disable=SC2154
|
||||||
#get_id "${args[project]}"
|
|
||||||
|
|
||||||
# check if stdin is present if selected
|
# check if stdin is present if selected
|
||||||
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
|
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
|
||||||
|
@ -8,12 +7,15 @@ if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# catch args, convert the space delimited string to an array
|
# catch args, convert the space delimited string to an array
|
||||||
files=()
|
files=()
|
||||||
eval "files=(${args[file]})"
|
eval "files=(${args[file]})"
|
||||||
|
|
||||||
# create tmp directory
|
# create tmp directory
|
||||||
tmpdir="$(mktemp -d)"
|
tmpdir="$(mktemp -d)"
|
||||||
trap 'rm -rf "$tmpdir"' 0 2 3 15
|
trap 'rm -rf "$tmpdir"' 0 2 3 15
|
||||||
|
|
||||||
# download files if name starts with http:// or https://
|
# download files if name starts with http:// or https://
|
||||||
for i in "${!files[@]}"; do
|
for i in "${!files[@]}"; do
|
||||||
if [[ ${files[$i]} == "http://"* ]] || [[ ${files[$i]} == "https://"* ]]; then
|
if [[ ${files[$i]} == "http://"* ]] || [[ ${files[$i]} == "https://"* ]]; then
|
||||||
|
@ -24,13 +26,24 @@ for i in "${!files[@]}"; do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# support multiple files and stdin
|
# support multiple files
|
||||||
readarray -t jsonlines < <(cat "${files[@]}" | jq --slurp --compact-output 'add | .[]')
|
for i in "${!files[@]}"; do
|
||||||
for line in "${jsonlines[@]}"; do
|
# read each operation into one line
|
||||||
declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
|
mapfile -t jsonlines < <(jq -c '.[]' "${files[$i]}")
|
||||||
echo "${data[op]#core/}"
|
for line in "${jsonlines[@]}"; do
|
||||||
unset "data[op]"
|
# parse operation into curl options
|
||||||
unset "data[description]"
|
declare -A data="($(echo "$line" | jq -r 'to_entries | map("[\(.key)]=" + @sh "\(.value|tostring)") | .[]'))"
|
||||||
for K in "${!data[@]}"; do echo "$K" --- "${data[$K]}"; done
|
op="${data[op]#core/}"
|
||||||
unset data
|
unset "data[op]"
|
||||||
|
unset "data[description]"
|
||||||
|
mapfile -t curloptions < <(for K in "${!data[@]}"; do
|
||||||
|
echo "--data-urlencode"
|
||||||
|
echo "$K={data[$K]}"
|
||||||
|
done)
|
||||||
|
# get project id and csrf token; post data to it's individual endpoint
|
||||||
|
if ! curl -fs --data "project=$(get_id "${args[project]}")" "${curloptions[@]}" "${OPENREFINE_URL}/command/core/${op}$(get_csrf)"; then
|
||||||
|
error "applying ${op} from ${files[$i]} failed!"
|
||||||
|
fi
|
||||||
|
unset data
|
||||||
|
done
|
||||||
done
|
done
|
Loading…
Reference in New Issue