2023-01-12 11:18:06 +01:00
|
|
|
# shellcheck shell=bash disable=SC2154
|
2022-04-13 13:36:23 +02:00
|
|
|
|
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
|
2023-01-12 11:18:06 +01:00
|
|
|
if [[ ${file} == '-' ]] && ! read -u 0 -t 0; then
|
|
|
|
orcli_import_csv_usage
|
|
|
|
exit 1
|
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
|
2022-12-13 23:40:10 +01:00
|
|
|
if [[ ${args[--blankCellsAsStrings]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+='"storeBlankCellsAsNulls": false'
|
|
|
|
fi
|
2023-01-09 11:38:53 +01:00
|
|
|
if [[ ${args[--columnNames]} ]]; then
|
|
|
|
IFS=',' read -ra columnNames <<< "${args[--columnNames]}"
|
|
|
|
options+=', '
|
|
|
|
options+="\"columnNames\": [ $(printf ',"'%s'"' "${columnNames[@]}" | cut -c2-) ]"
|
|
|
|
fi
|
2022-12-13 23:40:10 +01:00
|
|
|
if [[ ${args[--guessCellValueTypes]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+='"guessCellValueTypes": true'
|
|
|
|
fi
|
|
|
|
if [[ ${args[--headerLines]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+="\"headerLines\": ${args[--headerLines]}"
|
|
|
|
fi
|
|
|
|
if [[ ${args[--ignoreLines]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+="\"ignoreLines\": ${args[--ignoreLines]}"
|
|
|
|
fi
|
|
|
|
if [[ ${args[--ignoreQuoteCharacter]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+='"processQuotes": false'
|
|
|
|
fi
|
|
|
|
if [[ ${args[--includeFileSources]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+='includeFileSources: true'
|
|
|
|
fi
|
|
|
|
if [[ ${args[--includeArchiveFileName]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+='"includeArchiveFileName": true'
|
|
|
|
fi
|
|
|
|
if [[ ${args[--limit]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+="\"limit\": ${args[--limit]}"
|
|
|
|
fi
|
|
|
|
if [[ ${args[--quoteCharacter]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+="\"quoteCharacter\": \"${args[--quoteCharacter]}\""
|
|
|
|
fi
|
|
|
|
if [[ ${args[--skipBlankRows]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+='"storeBlankRows": false'
|
|
|
|
fi
|
|
|
|
if [[ ${args[--skipDataLines]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+="\"skipDataLines\": ${args[--skipDataLines]}"
|
|
|
|
fi
|
2023-10-28 18:07:08 +02:00
|
|
|
if [[ ${args[--projectName]} ]]; then
|
2022-04-13 23:55:47 +02:00
|
|
|
options+=', '
|
2023-10-28 18:07:08 +02:00
|
|
|
options+="\"projectName\": \"${args[--projectName]}\""
|
2022-04-13 13:36:23 +02:00
|
|
|
fi
|
2023-01-09 11:38:53 +01:00
|
|
|
if [[ ${args[--projectTags]} ]]; then
|
|
|
|
IFS=',' read -ra projectTags <<< "${args[--projectTags]}"
|
|
|
|
options+=', '
|
|
|
|
options+="\"projectTags\": [ $(printf ',"'%s'"' "${projectTags[@]}" | cut -c2-) ]"
|
|
|
|
fi
|
2023-10-28 18:07:08 +02:00
|
|
|
if [[ ${args[--trimStrings]} ]]; then
|
|
|
|
options+=', '
|
|
|
|
options+='"trimStrings": true'
|
|
|
|
fi
|
2022-04-13 13:36:23 +02:00
|
|
|
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[@]}"
|