Merge pull request #82 from opencultureconsulting:felixlohmeier/refactor-export-tsv-77

move part of export to lib file
This commit is contained in:
Felix Lohmeier 2022-11-16 16:39:10 +01:00 committed by GitHub
commit b39f2b9946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 38 deletions

47
orcli
View File

@ -686,6 +686,32 @@ function log() {
fi
}
# src/lib/post_export.sh
# post to export-rows endpoint
# shellcheck shell=bash disable=SC2154
function post_export() {
local curloptions
# post
mapfile -t curloptions < <(for d in "$@"; 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
error "exporting ${args[project]} failed!"
else
if [[ ${args[--output]} ]]; then
log "exported ${args[project]}" "file: ${args[--output]}" "rows: $(wc -l <"${args[--output]}")"
fi
fi
}
# src/lib/post_import.sh
# post to create-project endpoint and validate
# shellcheck shell=bash disable=SC2154
@ -998,25 +1024,8 @@ orcli_export_tsv_command() {
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
error "exporting ${args[project]} failed!"
else
if [[ ${args[--output]} ]]; then
log "exported ${args[project]}" "file: ${args[--output]}" "rows: $(wc -l <"${args[--output]}")"
fi
fi
# call post_export function to post data and validate results
post_export "${data[@]}"
}

View File

@ -14,22 +14,5 @@ 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
error "exporting ${args[project]} failed!"
else
if [[ ${args[--output]} ]]; then
log "exported ${args[project]}" "file: ${args[--output]}" "rows: $(wc -l <"${args[--output]}")"
fi
fi
# call post_export function to post data and validate results
post_export "${data[@]}"

24
src/lib/post_export.sh Normal file
View File

@ -0,0 +1,24 @@
# post to export-rows endpoint
# shellcheck shell=bash disable=SC2154
function post_export() {
local curloptions
# post
mapfile -t curloptions < <(for d in "$@"; 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
error "exporting ${args[project]} failed!"
else
if [[ ${args[--output]} ]]; then
log "exported ${args[project]}" "file: ${args[--output]}" "rows: $(wc -l <"${args[--output]}")"
fi
fi
}