orcli/src/import_csv_command.sh

31 lines
803 B
Bash
Raw Normal View History

2022-04-13 13:36:23 +02:00
# shellcheck shell=bash
2022-04-13 23:55:47 +02:00
# call init_import function to eval args and to set basic post data
init_import
# check if stdin is present if selected
2022-10-15 22:57:07 +02:00
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
if ! read -u 0 -t 0; then
orcli_import_csv_usage
exit 1
fi
2022-04-13 13:36:23 +02:00
fi
2022-04-13 23:55:47 +02:00
# assemble specific post data (some options require json format)
data+=("format=text/line-based/*sv")
2022-04-13 13:36:23 +02:00
options='{ '
options+="\"separator\": \"${args[--separator]}\""
if [[ ${args[--encoding]} ]]; then
2022-04-13 23:55:47 +02:00
options+=', '
options+="\"encoding\": \"${args[--encoding]}\""
2022-04-13 13:36:23 +02:00
fi
if [[ ${args[--trimStrings]} ]]; then
2022-04-13 23:55:47 +02:00
options+=', '
options+="\"trimStrings\": true"
2022-04-13 13:36:23 +02:00
fi
options+=' }'
2022-04-13 23:55:47 +02:00
data+=("options=${options}")
2022-04-13 13:36:23 +02:00
2022-04-13 23:55:47 +02:00
# call post_import function to post data and validate results
post_import "${data[@]}"