support stdin
This commit is contained in:
parent
f61fbdecf2
commit
8144831bf7
64
orcli
64
orcli
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# This script was generated by bashly 0.8.7 (https://bashly.dannyb.co)
|
# This script was generated by bashly 0.8.9 (https://bashly.dannyb.co)
|
||||||
# Modifying it manually is not recommended
|
# Modifying it manually is not recommended
|
||||||
|
|
||||||
# :wrapper.bash3_bouncer
|
# :wrapper.bash3_bouncer
|
||||||
|
@ -35,7 +35,7 @@ orcli_usage() {
|
||||||
# :command.usage_commands
|
# :command.usage_commands
|
||||||
printf "Commands:\n"
|
printf "Commands:\n"
|
||||||
echo " completions Generate bash completions"
|
echo " completions Generate bash completions"
|
||||||
echo " batch run tmp OpenRefine workspace and execute shell script"
|
echo " batch run tmp OpenRefine workspace and execute shell script(s)"
|
||||||
echo " import import commands"
|
echo " import import commands"
|
||||||
echo " list list projects on OpenRefine server"
|
echo " list list projects on OpenRefine server"
|
||||||
echo " info show project metadata"
|
echo " info show project metadata"
|
||||||
|
@ -121,11 +121,11 @@ orcli_completions_usage() {
|
||||||
# :command.usage
|
# :command.usage
|
||||||
orcli_batch_usage() {
|
orcli_batch_usage() {
|
||||||
if [[ -n $long_usage ]]; then
|
if [[ -n $long_usage ]]; then
|
||||||
printf "orcli batch - run tmp OpenRefine workspace and execute shell script\n"
|
printf "orcli batch - run tmp OpenRefine workspace and execute shell script(s)\n"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
else
|
else
|
||||||
printf "orcli batch - run tmp OpenRefine workspace and execute shell script\n"
|
printf "orcli batch - run tmp OpenRefine workspace and execute shell script(s)\n"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -158,8 +158,8 @@ orcli_batch_usage() {
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# :flag.usage
|
# :flag.usage
|
||||||
echo " --interactive"
|
echo " --debug"
|
||||||
printf " provide interactive Bash shell for playground and debugging\n"
|
printf " do not exit on error and keep shell open\n"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# :command.usage_args
|
# :command.usage_args
|
||||||
|
@ -173,7 +173,6 @@ orcli_batch_usage() {
|
||||||
|
|
||||||
# :command.usage_examples
|
# :command.usage_examples
|
||||||
printf "Examples:\n"
|
printf "Examples:\n"
|
||||||
printf " orcli batch --interactive\n"
|
|
||||||
printf " orcli batch << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli info \"duplicates\"\n orcli export tsv \"duplicates\"\n EOF\n"
|
printf " orcli batch << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli info \"duplicates\"\n orcli export tsv \"duplicates\"\n EOF\n"
|
||||||
printf " orcli batch --memory \"2000M\" --port \"3334\" << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\" &\n orcli import csv \"https://git.io/fj5hF\" --projectName \"copy\" &\n wait\n echo \"finished import\"\n orcli export csv \"duplicates\" --output duplicates.csv &\n orcli export tsv \"duplicates\" --output duplicates.tsv &\n wait\n wc duplicates*\n EOF\n"
|
printf " orcli batch --memory \"2000M\" --port \"3334\" << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\" &\n orcli import csv \"https://git.io/fj5hF\" --projectName \"copy\" &\n wait\n echo \"finished import\"\n orcli export csv \"duplicates\" --output duplicates.csv &\n orcli export tsv \"duplicates\" --output duplicates.tsv &\n wait\n wc duplicates*\n EOF\n"
|
||||||
printf " orcli batch \"file1.sh\" \"file2.sh\" - << EOF\n echo \"finished in \$SECONDS seconds\"\n EOF\n"
|
printf " orcli batch \"file1.sh\" \"file2.sh\" - << EOF\n echo \"finished in \$SECONDS seconds\"\n EOF\n"
|
||||||
|
@ -704,7 +703,7 @@ send_completions() {
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' \'batch\'*)'
|
echo $' \'batch\'*)'
|
||||||
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port -h")" -- "$cur" )'
|
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--debug --help --memory --port -h")" -- "$cur" )'
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' \'list\'*)'
|
echo $' \'list\'*)'
|
||||||
|
@ -742,14 +741,6 @@ orcli_batch_command() {
|
||||||
# src/batch_command.sh
|
# src/batch_command.sh
|
||||||
# shellcheck shell=bash disable=SC2154 source=/dev/null
|
# shellcheck shell=bash disable=SC2154 source=/dev/null
|
||||||
|
|
||||||
# check if stdin is present if selected
|
|
||||||
if ! [[ ${args[--interactive]} ]]; then
|
|
||||||
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]] && [ -t 0 ]; then
|
|
||||||
orcli_batch_usage
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# catch args, convert the space delimited string to an array
|
# catch args, convert the space delimited string to an array
|
||||||
files=()
|
files=()
|
||||||
eval "files=(${args[file]})"
|
eval "files=(${args[file]})"
|
||||||
|
@ -794,19 +785,32 @@ orcli_batch_command() {
|
||||||
log "started OpenRefine" "port: ${args[--port]}" "memory: ${args[--memory]}" "tmpdir: ${tmpdir}" "pid: ${openrefine_pid}"
|
log "started OpenRefine" "port: ${args[--port]}" "memory: ${args[--memory]}" "tmpdir: ${tmpdir}" "pid: ${openrefine_pid}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# execute shell script
|
# execute script(s) in subshell
|
||||||
export orcli tmpdir OPENREFINE_URL openrefine_pid
|
export orcli tmpdir OPENREFINE_URL openrefine_pid
|
||||||
if [[ ${args[--interactive]} ]]; then
|
# case 1: interactive mode if stdin is selected but not present
|
||||||
|
if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
|
||||||
|
if ! read -u 0 -t 0; then
|
||||||
|
bash --rcfile <(
|
||||||
|
cat ~/.bashrc
|
||||||
|
interactive
|
||||||
|
) -i < /dev/tty
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# case 2: execute scripts and keep shell running
|
||||||
|
if [[ ${args[--debug]} ]]; then
|
||||||
bash --rcfile <(
|
bash --rcfile <(
|
||||||
cat ~/.bashrc
|
cat ~/.bashrc
|
||||||
|
for i in "${!files[@]}"; do log "execute script ${files[$i]}"; awk 1 "${files[$i]}"; done
|
||||||
interactive
|
interactive
|
||||||
if ! [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
|
) -i < /dev/tty
|
||||||
awk 1 "${files[@]}"
|
exit
|
||||||
fi
|
|
||||||
) -i
|
|
||||||
else
|
|
||||||
bash -e <(awk 1 "${files[@]}")
|
|
||||||
fi
|
fi
|
||||||
|
# case 3: execute scripts
|
||||||
|
for i in "${!files[@]}"; do
|
||||||
|
log "execute script ${files[$i]}"
|
||||||
|
bash -e <(awk 1 "${files[$i]}")
|
||||||
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,9 +823,11 @@ orcli_import_csv_command() {
|
||||||
init_import
|
init_import
|
||||||
|
|
||||||
# check if stdin is present if selected
|
# check if stdin is present if selected
|
||||||
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]] && [ -t 0 ]; then
|
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
|
||||||
orcli_import_csv_usage
|
if ! read -u 0 -t 0; then
|
||||||
exit 1
|
orcli_import_csv_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# assemble specific post data (some options require json format)
|
# assemble specific post data (some options require json format)
|
||||||
|
@ -1122,10 +1128,10 @@ orcli_batch_parse_requirements() {
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# :flag.case
|
# :flag.case
|
||||||
--interactive )
|
--debug )
|
||||||
|
|
||||||
# :flag.case_no_arg
|
# :flag.case_no_arg
|
||||||
args[--interactive]=1
|
args[--debug]=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ commands:
|
||||||
Usage: eval "\$(orcli completions)"
|
Usage: eval "\$(orcli completions)"
|
||||||
|
|
||||||
- name: batch
|
- name: batch
|
||||||
help: run tmp OpenRefine workspace and execute shell script
|
help: run tmp OpenRefine workspace and execute shell script(s)
|
||||||
args:
|
args:
|
||||||
- name: file
|
- name: file
|
||||||
help: Path to one or more files. When FILE is -, read standard input.
|
help: Path to one or more files. When FILE is -, read standard input.
|
||||||
|
@ -52,10 +52,9 @@ commands:
|
||||||
help: PORT on which OpenRefine should listen
|
help: PORT on which OpenRefine should listen
|
||||||
arg: port
|
arg: port
|
||||||
default: "3333"
|
default: "3333"
|
||||||
- long: --interactive
|
- long: --debug
|
||||||
help: provide interactive Bash shell for playground and debugging
|
help: do not exit on error and keep shell open
|
||||||
examples:
|
examples:
|
||||||
- orcli batch --interactive
|
|
||||||
- |-
|
- |-
|
||||||
orcli batch << EOF
|
orcli batch << EOF
|
||||||
orcli import csv "https://git.io/fj5hF" --projectName "duplicates"
|
orcli import csv "https://git.io/fj5hF" --projectName "duplicates"
|
||||||
|
|
|
@ -1,13 +1,5 @@
|
||||||
# shellcheck shell=bash disable=SC2154 source=/dev/null
|
# shellcheck shell=bash disable=SC2154 source=/dev/null
|
||||||
|
|
||||||
# check if stdin is present if selected
|
|
||||||
if ! [[ ${args[--interactive]} ]]; then
|
|
||||||
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]] && [ -t 0 ]; then
|
|
||||||
orcli_batch_usage
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# catch args, convert the space delimited string to an array
|
# catch args, convert the space delimited string to an array
|
||||||
files=()
|
files=()
|
||||||
eval "files=(${args[file]})"
|
eval "files=(${args[file]})"
|
||||||
|
@ -52,16 +44,29 @@ else
|
||||||
log "started OpenRefine" "port: ${args[--port]}" "memory: ${args[--memory]}" "tmpdir: ${tmpdir}" "pid: ${openrefine_pid}"
|
log "started OpenRefine" "port: ${args[--port]}" "memory: ${args[--memory]}" "tmpdir: ${tmpdir}" "pid: ${openrefine_pid}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# execute shell script
|
# execute script(s) in subshell
|
||||||
export orcli tmpdir OPENREFINE_URL openrefine_pid
|
export orcli tmpdir OPENREFINE_URL openrefine_pid
|
||||||
if [[ ${args[--interactive]} ]]; then
|
# case 1: interactive mode if stdin is selected but not present
|
||||||
|
if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
|
||||||
|
if ! read -u 0 -t 0; then
|
||||||
|
bash --rcfile <(
|
||||||
|
cat ~/.bashrc
|
||||||
|
interactive
|
||||||
|
) -i < /dev/tty
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# case 2: execute scripts and keep shell running
|
||||||
|
if [[ ${args[--debug]} ]]; then
|
||||||
bash --rcfile <(
|
bash --rcfile <(
|
||||||
cat ~/.bashrc
|
cat ~/.bashrc
|
||||||
|
for i in "${!files[@]}"; do log "execute script ${files[$i]}"; awk 1 "${files[$i]}"; done
|
||||||
interactive
|
interactive
|
||||||
if ! [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
|
) -i < /dev/tty
|
||||||
awk 1 "${files[@]}"
|
exit
|
||||||
fi
|
|
||||||
) -i
|
|
||||||
else
|
|
||||||
bash -e <(awk 1 "${files[@]}")
|
|
||||||
fi
|
fi
|
||||||
|
# case 3: execute scripts
|
||||||
|
for i in "${!files[@]}"; do
|
||||||
|
log "execute script ${files[$i]}"
|
||||||
|
bash -e <(awk 1 "${files[$i]}")
|
||||||
|
done
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
init_import
|
init_import
|
||||||
|
|
||||||
# check if stdin is present if selected
|
# check if stdin is present if selected
|
||||||
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]] && [ -t 0 ]; then
|
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
|
||||||
orcli_import_csv_usage
|
if ! read -u 0 -t 0; then
|
||||||
exit 1
|
orcli_import_csv_usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# assemble specific post data (some options require json format)
|
# assemble specific post data (some options require json format)
|
||||||
|
|
|
@ -51,7 +51,7 @@ send_completions() {
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' \'batch\'*)'
|
echo $' \'batch\'*)'
|
||||||
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port -h")" -- "$cur" )'
|
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--debug --help --memory --port -h")" -- "$cur" )'
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' \'list\'*)'
|
echo $' \'list\'*)'
|
||||||
|
|
Loading…
Reference in New Issue