2022-04-14 12:06:54 +02:00
|
|
|
# shellcheck shell=bash
|
|
|
|
projectid="$(get_id "${args[project]}")"
|
|
|
|
separator='\t'
|
|
|
|
|
|
|
|
# assemble specific post data (some options require json format)
|
|
|
|
data+=("project=${projectid}")
|
|
|
|
data+=("format=tsv")
|
|
|
|
options='{ '
|
|
|
|
options+="\"separator\": \"${separator}\""
|
|
|
|
if [[ ${args[--encoding]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+="\"encoding\": \"${args[--encoding]}\""
|
|
|
|
fi
|
|
|
|
options+=' }'
|
|
|
|
data+=("options=${options}")
|
|
|
|
|
|
|
|
# post
|
|
|
|
mapfile -t curloptions < <(for d in "${data[@]}"; do
|
|
|
|
echo "--data"
|
|
|
|
echo "$d"
|
|
|
|
done)
|
|
|
|
if [[ ${args[--output]} ]]; then
|
|
|
|
if ! mkdir -p "$(dirname "${args[--output]}")"; then
|
|
|
|
error "unable to create parent directory for ${args[--output]}"
|
|
|
|
fi
|
|
|
|
curloptions+=("--output")
|
|
|
|
curloptions+=("${args[--output]}")
|
|
|
|
fi
|
|
|
|
if ! curl -fs "${curloptions[@]}" "${OPENREFINE_URL}/command/core/export-rows"; then
|
2022-04-20 12:27:53 +02:00
|
|
|
error "exporting ${args[project]} failed!"
|
2022-04-14 12:06:54 +02:00
|
|
|
else
|
|
|
|
if [[ ${args[--output]} ]]; then
|
2022-04-20 12:27:53 +02:00
|
|
|
log "exported ${args[project]}" "file: ${args[--output]}" "rows: $(wc -l <"${args[--output]}")"
|
2022-04-14 12:06:54 +02:00
|
|
|
fi
|
|
|
|
fi
|