export tsv --select
This commit is contained in:
parent
f8e5b4abbd
commit
ed65302b30
|
@ -8,6 +8,10 @@ Usage:
|
||||||
orcli export tsv --help | -h
|
orcli export tsv --help | -h
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
--select COLUMNS
|
||||||
|
filter result set to one or more columns (comma separated)
|
||||||
|
example: --select "foo,bar,baz"
|
||||||
|
|
||||||
--mode MODE
|
--mode MODE
|
||||||
specify if project contains multi-row records
|
specify if project contains multi-row records
|
||||||
Allowed: rows, records
|
Allowed: rows, records
|
||||||
|
@ -38,6 +42,7 @@ Examples:
|
||||||
orcli export tsv "duplicates"
|
orcli export tsv "duplicates"
|
||||||
orcli export tsv "duplicates" --output "duplicates.tsv"
|
orcli export tsv "duplicates" --output "duplicates.tsv"
|
||||||
orcli export tsv "duplicates" --encoding "ISO-8859-1"
|
orcli export tsv "duplicates" --encoding "ISO-8859-1"
|
||||||
|
orcli export tsv "duplicates" --select "name,email,purchase"
|
||||||
orcli export tsv "duplicates" --facets '[ { "type": "text", "columnName":
|
orcli export tsv "duplicates" --facets '[ { "type": "text", "columnName":
|
||||||
"name", "mode": "regex", "caseSensitive": false, "invert": false, "query":
|
"name", "mode": "regex", "caseSensitive": false, "invert": false, "query":
|
||||||
"^Ben" } ]'
|
"^Ben" } ]'
|
||||||
|
|
38
orcli
38
orcli
|
@ -1056,6 +1056,11 @@ orcli_export_tsv_usage() {
|
||||||
printf "%s\n" "Options:"
|
printf "%s\n" "Options:"
|
||||||
|
|
||||||
# :command.usage_flags
|
# :command.usage_flags
|
||||||
|
# :flag.usage
|
||||||
|
printf " %s\n" "--select COLUMNS"
|
||||||
|
printf " filter result set to one or more columns (comma separated)\n example: --select \"foo,bar,baz\"\n"
|
||||||
|
echo
|
||||||
|
|
||||||
# :flag.usage
|
# :flag.usage
|
||||||
printf " %s\n" "--mode MODE"
|
printf " %s\n" "--mode MODE"
|
||||||
printf " specify if project contains multi-row records\n"
|
printf " specify if project contains multi-row records\n"
|
||||||
|
@ -1103,6 +1108,7 @@ orcli_export_tsv_usage() {
|
||||||
printf " orcli export tsv \"duplicates\"\n"
|
printf " orcli export tsv \"duplicates\"\n"
|
||||||
printf " orcli export tsv \"duplicates\" --output \"duplicates.tsv\"\n"
|
printf " orcli export tsv \"duplicates\" --output \"duplicates.tsv\"\n"
|
||||||
printf " orcli export tsv \"duplicates\" --encoding \"ISO-8859-1\"\n"
|
printf " orcli export tsv \"duplicates\" --encoding \"ISO-8859-1\"\n"
|
||||||
|
printf " orcli export tsv \"duplicates\" --select \"name,email,purchase\"\n"
|
||||||
printf " orcli export tsv \"duplicates\" --facets '[ { \"type\": \"text\", \"columnName\":\n \"name\", \"mode\": \"regex\", \"caseSensitive\": false, \"invert\": false, \"query\":\n \"^Ben\" } ]'\n"
|
printf " orcli export tsv \"duplicates\" --facets '[ { \"type\": \"text\", \"columnName\":\n \"name\", \"mode\": \"regex\", \"caseSensitive\": false, \"invert\": false, \"query\":\n \"^Ben\" } ]'\n"
|
||||||
printf " orcli export tsv \"duplicates\" --facets '[{ \"type\": \"list\", \"expression\":\n \"grel:filter([\\\\\"gender\\\\\",\\\\\"purchase\\\\\"],cn,cells[cn].value.find(/^F/).length()>0).length()>0\",\n \"columnName\": \"\", \"selection\": [{\"v\": {\"v\": true}}] }]'\n"
|
printf " orcli export tsv \"duplicates\" --facets '[{ \"type\": \"list\", \"expression\":\n \"grel:filter([\\\\\"gender\\\\\",\\\\\"purchase\\\\\"],cn,cells[cn].value.find(/^F/).length()>0).length()>0\",\n \"columnName\": \"\", \"selection\": [{\"v\": {\"v\": true}}] }]'\n"
|
||||||
echo
|
echo
|
||||||
|
@ -1617,7 +1623,7 @@ send_completions() {
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' \'export tsv\'*)'
|
echo $' \'export tsv\'*)'
|
||||||
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet -h -q")" -- "$cur" )'
|
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select -h -q")" -- "$cur" )'
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' \'transform\'*)'
|
echo $' \'transform\'*)'
|
||||||
|
@ -2367,6 +2373,21 @@ orcli_export_tsv_command() {
|
||||||
options+=', '
|
options+=', '
|
||||||
options+="\"encoding\": \"${args[--encoding]}\""
|
options+="\"encoding\": \"${args[--encoding]}\""
|
||||||
fi
|
fi
|
||||||
|
if [[ ${args[--select]} ]]; then
|
||||||
|
options+=', '
|
||||||
|
options+='"columns": ['
|
||||||
|
IFS=',' read -ra columns <<< "${args[--select]}"
|
||||||
|
options+='{"name":"'
|
||||||
|
options+="${columns[0]}"
|
||||||
|
options+='"}'
|
||||||
|
for cn in "${columns[@]:1}"; do
|
||||||
|
options+=', '
|
||||||
|
options+='{"name":"'
|
||||||
|
options+="${cn}"
|
||||||
|
options+='"}'
|
||||||
|
done
|
||||||
|
options+="]"
|
||||||
|
fi
|
||||||
options+=' }'
|
options+=' }'
|
||||||
data+=("options=${options}")
|
data+=("options=${options}")
|
||||||
|
|
||||||
|
@ -4316,6 +4337,21 @@ orcli_export_tsv_parse_requirements() {
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
key="$1"
|
key="$1"
|
||||||
case "$key" in
|
case "$key" in
|
||||||
|
# :flag.case
|
||||||
|
--select)
|
||||||
|
|
||||||
|
# :flag.case_arg
|
||||||
|
if [[ -n ${2+x} ]]; then
|
||||||
|
|
||||||
|
args['--select']="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
else
|
||||||
|
printf "%s\n" "--select requires an argument: --select COLUMNS" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
# :flag.case
|
# :flag.case
|
||||||
--mode)
|
--mode)
|
||||||
|
|
||||||
|
|
|
@ -360,6 +360,11 @@ commands:
|
||||||
args:
|
args:
|
||||||
- *project
|
- *project
|
||||||
flags:
|
flags:
|
||||||
|
- long: --select
|
||||||
|
help: |-
|
||||||
|
filter result set to one or more columns (comma separated)
|
||||||
|
example: --select "foo,bar,baz"
|
||||||
|
arg: columns
|
||||||
- *mode
|
- *mode
|
||||||
- *facets
|
- *facets
|
||||||
- *output
|
- *output
|
||||||
|
@ -369,6 +374,7 @@ commands:
|
||||||
- orcli export tsv "duplicates"
|
- orcli export tsv "duplicates"
|
||||||
- orcli export tsv "duplicates" --output "duplicates.tsv"
|
- orcli export tsv "duplicates" --output "duplicates.tsv"
|
||||||
- orcli export tsv "duplicates" --encoding "ISO-8859-1"
|
- orcli export tsv "duplicates" --encoding "ISO-8859-1"
|
||||||
|
- orcli export tsv "duplicates" --select "name,email,purchase"
|
||||||
- |-
|
- |-
|
||||||
orcli export tsv "duplicates" --facets '[ { "type": "text", "columnName": "name", "mode": "regex", "caseSensitive": false, "invert": false, "query": "^Ben" } ]'
|
orcli export tsv "duplicates" --facets '[ { "type": "text", "columnName": "name", "mode": "regex", "caseSensitive": false, "invert": false, "query": "^Ben" } ]'
|
||||||
- |-
|
- |-
|
||||||
|
|
|
@ -11,6 +11,21 @@ if [[ ${args[--encoding]} ]]; then
|
||||||
options+=', '
|
options+=', '
|
||||||
options+="\"encoding\": \"${args[--encoding]}\""
|
options+="\"encoding\": \"${args[--encoding]}\""
|
||||||
fi
|
fi
|
||||||
|
if [[ ${args[--select]} ]]; then
|
||||||
|
options+=', '
|
||||||
|
options+='"columns": ['
|
||||||
|
IFS=',' read -ra columns <<< "${args[--select]}"
|
||||||
|
options+='{"name":"'
|
||||||
|
options+="${columns[0]}"
|
||||||
|
options+='"}'
|
||||||
|
for cn in "${columns[@]:1}"; do
|
||||||
|
options+=', '
|
||||||
|
options+='{"name":"'
|
||||||
|
options+="${cn}"
|
||||||
|
options+='"}'
|
||||||
|
done
|
||||||
|
options+="]"
|
||||||
|
fi
|
||||||
options+=' }'
|
options+=' }'
|
||||||
data+=("options=${options}")
|
data+=("options=${options}")
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ send_completions() {
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' \'export tsv\'*)'
|
echo $' \'export tsv\'*)'
|
||||||
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet -h -q")" -- "$cur" )'
|
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--encoding --facets --help --mode --output --quiet --select -h -q")" -- "$cur" )'
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' \'transform\'*)'
|
echo $' \'transform\'*)'
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
t="export-tsv-select"
|
||||||
|
|
||||||
|
# create tmp directory
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# input
|
||||||
|
cp data/duplicates.csv "${tmpdir}/${t}.csv"
|
||||||
|
|
||||||
|
# assertion
|
||||||
|
cat << "DATA" > "${tmpdir}/${t}.assert"
|
||||||
|
name email purchase
|
||||||
|
Danny Baron danny.baron@example1.com TV
|
||||||
|
Melanie White melanie.white@example2.edu iPhone
|
||||||
|
D. Baron danny.baron@example1.com Winter jacket
|
||||||
|
Ben Tyler ben.tyler@example3.org Flashlight
|
||||||
|
Arthur Duff arthur.duff@example4.com Dining table
|
||||||
|
Daniel Baron danny.baron@example1.com Bike
|
||||||
|
Jean Griffith jean.griffith@example5.org Power drill
|
||||||
|
Melanie White melanie.white@example2.edu iPad
|
||||||
|
Ben Morisson ben.morisson@example6.org Amplifier
|
||||||
|
Arthur Duff arthur.duff@example4.com Night table
|
||||||
|
DATA
|
||||||
|
|
||||||
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
|
orcli import csv "${t}.csv" --projectName "${t}"
|
||||||
|
orcli export tsv "${t}" \
|
||||||
|
--output "${t}.output" \
|
||||||
|
--select "name,email,purchase"
|
||||||
|
|
||||||
|
# test
|
||||||
|
diff -u "${t}.assert" "${t}.output"
|
Loading…
Reference in New Issue