add import csv options

This commit is contained in:
felixlohmeier 2022-12-13 22:40:10 +00:00
parent fbf9b04188
commit 27ee2ef650
4 changed files with 331 additions and 4 deletions

240
orcli
View File

@ -238,11 +238,71 @@ orcli_import_csv_usage() {
printf " Default: ,\n" printf " Default: ,\n"
echo echo
# :flag.usage
echo " --blankCellsAsStrings"
printf " store blank cells as empty strings instead of nulls\n"
echo
# :flag.usage # :flag.usage
echo " --encoding ENCODING" echo " --encoding ENCODING"
printf " set character encoding\n" printf " set character encoding\n"
echo echo
# :flag.usage
echo " --guessCellValueTypes"
printf " attempt to parse cell text into numbers\n"
echo
# :flag.usage
echo " --headerLines HEADERLINES"
printf " parse x line(s) as column headers\n"
printf " Default: 1\n"
echo
# :flag.usage
echo " --ignoreLines IGNORELINES"
printf " ignore first x line(s) at beginning of file\n"
printf " Default: -1\n"
echo
# :flag.usage
echo " --ignoreQuoteCharacter"
printf " do not use any quote character to enclose cells containing column separators\n"
echo
# :flag.usage
echo " --includeFileSources"
printf " add column with file source\n"
echo
# :flag.usage
echo " --includeArchiveFileName"
printf " add column with archive file name\n"
echo
# :flag.usage
echo " --limit LIMIT"
printf " load at most x row(s) of data\n"
printf " Default: -1\n"
echo
# :flag.usage
echo " --quoteCharacter QUOTECHARACTER"
printf " quote character to enclose cells containing column separators\n"
printf " Default: \\\"\n"
echo
# :flag.usage
echo " --skipBlankRows"
printf " do not store blank rows\n"
echo
# :flag.usage
echo " --skipDataLines SKIPDATALINES"
printf " discard initial x row(s) of data\n"
printf " Default: 0\n"
echo
# :flag.usage # :flag.usage
echo " --trimStrings" echo " --trimStrings"
printf " trim leading & trailing whitespace from strings\n" printf " trim leading & trailing whitespace from strings\n"
@ -943,7 +1003,7 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import csv\'*)' echo $' \'import csv\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --projectName --quiet --separator --trimStrings -h -q")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --quiet --quoteCharacter --separator --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import tsv\'*)' echo $' \'import tsv\'*)'
@ -1061,9 +1121,57 @@ orcli_import_csv_command() {
options+=', ' options+=', '
options+="\"encoding\": \"${args[--encoding]}\"" options+="\"encoding\": \"${args[--encoding]}\""
fi fi
if [[ ${args[--blankCellsAsStrings]} ]]; then
options+=', '
options+='"storeBlankCellsAsNulls": false'
fi
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[--projectName]} ]]; then
options+=', '
options+="\"projectName\": \"${args[--projectName]}\""
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
if [[ ${args[--trimStrings]} ]]; then if [[ ${args[--trimStrings]} ]]; then
options+=', ' options+=', '
options+="\"trimStrings\": true" options+='"trimStrings": true'
fi fi
options+=' }' options+=' }'
data+=("options=${options}") data+=("options=${options}")
@ -1848,6 +1956,14 @@ orcli_import_csv_parse_requirements() {
fi fi
;; ;;
# :flag.case
--blankCellsAsStrings)
# :flag.case_no_arg
args[--blankCellsAsStrings]=1
shift
;;
# :flag.case # :flag.case
--encoding) --encoding)
@ -1863,6 +1979,121 @@ orcli_import_csv_parse_requirements() {
fi fi
;; ;;
# :flag.case
--guessCellValueTypes)
# :flag.case_no_arg
args[--guessCellValueTypes]=1
shift
;;
# :flag.case
--headerLines)
# :flag.case_arg
if [[ -n ${2+x} ]]; then
args[--headerLines]="$2"
shift
shift
else
printf "%s\n" "--headerLines requires an argument: --headerLines HEADERLINES" >&2
exit 1
fi
;;
# :flag.case
--ignoreLines)
# :flag.case_arg
if [[ -n ${2+x} ]]; then
args[--ignoreLines]="$2"
shift
shift
else
printf "%s\n" "--ignoreLines requires an argument: --ignoreLines IGNORELINES" >&2
exit 1
fi
;;
# :flag.case
--ignoreQuoteCharacter)
# :flag.case_no_arg
args[--ignoreQuoteCharacter]=1
shift
;;
# :flag.case
--includeFileSources)
# :flag.case_no_arg
args[--includeFileSources]=1
shift
;;
# :flag.case
--includeArchiveFileName)
# :flag.case_no_arg
args[--includeArchiveFileName]=1
shift
;;
# :flag.case
--limit)
# :flag.case_arg
if [[ -n ${2+x} ]]; then
args[--limit]="$2"
shift
shift
else
printf "%s\n" "--limit requires an argument: --limit LIMIT" >&2
exit 1
fi
;;
# :flag.case
--quoteCharacter)
# :flag.case_arg
if [[ -n ${2+x} ]]; then
args[--quoteCharacter]="$2"
shift
shift
else
printf "%s\n" "--quoteCharacter requires an argument: --quoteCharacter QUOTECHARACTER" >&2
exit 1
fi
;;
# :flag.case
--skipBlankRows)
# :flag.case_no_arg
args[--skipBlankRows]=1
shift
;;
# :flag.case
--skipDataLines)
# :flag.case_arg
if [[ -n ${2+x} ]]; then
args[--skipDataLines]="$2"
shift
shift
else
printf "%s\n" "--skipDataLines requires an argument: --skipDataLines SKIPDATALINES" >&2
exit 1
fi
;;
# :flag.case # :flag.case
--trimStrings) --trimStrings)
@ -1919,6 +2150,11 @@ orcli_import_csv_parse_requirements() {
# :command.default_assignments # :command.default_assignments
[[ -n ${args[file]:-} ]] || args[file]="-" [[ -n ${args[file]:-} ]] || args[file]="-"
[[ -n ${args[--separator]:-} ]] || args[--separator]="," [[ -n ${args[--separator]:-} ]] || args[--separator]=","
[[ -n ${args[--headerLines]:-} ]] || args[--headerLines]="1"
[[ -n ${args[--ignoreLines]:-} ]] || args[--ignoreLines]="-1"
[[ -n ${args[--limit]:-} ]] || args[--limit]="-1"
[[ -n ${args[--quoteCharacter]:-} ]] || args[--quoteCharacter]="\\\""
[[ -n ${args[--skipDataLines]:-} ]] || args[--skipDataLines]="0"
} }

View File

@ -70,10 +70,53 @@ commands:
help: character(s) that separates columns help: character(s) that separates columns
arg: separator arg: separator
default: "," default: ","
- &blankCellsAsStrings
long: --blankCellsAsStrings
help: store blank cells as empty strings instead of nulls
- &encoding_import - &encoding_import
long: --encoding long: --encoding
help: set character encoding help: set character encoding
arg: encoding arg: encoding
- &guessCellValueTypes
long: --guessCellValueTypes
help: attempt to parse cell text into numbers
- &headerLines
long: --headerLines
help: parse x line(s) as column headers
arg: headerLines
default: "1"
- &ignoreLines
long: --ignoreLines
help: ignore first x line(s) at beginning of file
arg: ignoreLines
default: "-1"
- &ignoreQuoteCharacter
long: --ignoreQuoteCharacter
help: do not use any quote character to enclose cells containing column separators
- &includeFileSources
long: --includeFileSources
help: add column with file source
- &includeArchiveFileName
long: --includeArchiveFileName
help: add column with archive file name
- &limit
long: --limit
help: load at most x row(s) of data
arg: limit
default: "-1"
- &quoteCharacter
long: --quoteCharacter
help: quote character to enclose cells containing column separators
arg: quoteCharacter
default: '\\\"'
- &skipBlankRows
long: --skipBlankRows
help: do not store blank rows
- &skipDataLines
long: --skipDataLines
help: discard initial x row(s) of data
arg: skipDataLines
default: "0"
- &trimStrings - &trimStrings
long: --trimStrings long: --trimStrings
help: trim leading & trailing whitespace from strings help: trim leading & trailing whitespace from strings

View File

@ -19,9 +19,57 @@ if [[ ${args[--encoding]} ]]; then
options+=', ' options+=', '
options+="\"encoding\": \"${args[--encoding]}\"" options+="\"encoding\": \"${args[--encoding]}\""
fi fi
if [[ ${args[--blankCellsAsStrings]} ]]; then
options+=', '
options+='"storeBlankCellsAsNulls": false'
fi
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[--projectName]} ]]; then
options+=', '
options+="\"projectName\": \"${args[--projectName]}\""
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
if [[ ${args[--trimStrings]} ]]; then if [[ ${args[--trimStrings]} ]]; then
options+=', ' options+=', '
options+="\"trimStrings\": true" options+='"trimStrings": true'
fi fi
options+=' }' options+=' }'
data+=("options=${options}") data+=("options=${options}")

View File

@ -35,7 +35,7 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import csv\'*)' echo $' \'import csv\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --help --projectName --quiet --separator --trimStrings -h -q")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--blankCellsAsStrings --encoding --guessCellValueTypes --headerLines --help --ignoreLines --ignoreQuoteCharacter --includeArchiveFileName --includeFileSources --limit --projectName --quiet --quoteCharacter --separator --skipBlankRows --skipDataLines --trimStrings -h -q")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'import tsv\'*)' echo $' \'import tsv\'*)'