move part of export to lib file
This commit is contained in:
parent
7032bb20b2
commit
98fa74a7ca
47
orcli
47
orcli
|
@ -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[@]}"
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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[@]}"
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue