Merge pull request #68 from opencultureconsulting:felixlohmeier/run-interactive-61

revert to --interactive
This commit is contained in:
Felix Lohmeier 2022-10-16 23:15:52 +02:00 committed by GitHub
commit 6ab1ab171c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 28 deletions

34
orcli
View File

@ -76,6 +76,7 @@ orcli_usage() {
printf " orcli info \"duplicates\"\n" printf " orcli info \"duplicates\"\n"
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 run --interactive\n"
printf " orcli run << 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 run << EOF\n orcli import csv \"https://git.io/fj5hF\" --projectName \"duplicates\"\n orcli info \"duplicates\"\n orcli export tsv \"duplicates\"\n EOF\n"
echo echo
@ -420,8 +421,8 @@ orcli_run_usage() {
echo echo
# :flag.usage # :flag.usage
echo " --debug" echo " --interactive"
printf " do not exit on error and keep shell open\n" printf " do not exit on error and keep bash shell open\n"
echo echo
# :command.usage_args # :command.usage_args
@ -435,9 +436,10 @@ orcli_run_usage() {
# :command.usage_examples # :command.usage_examples
printf "Examples:\n" printf "Examples:\n"
printf " orcli run --interactive\n"
printf " orcli run << 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 run << 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 run --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 run --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 run \"file1.sh\" \"file2.sh\" - << EOF\n echo \"finished in \$SECONDS seconds\"\n EOF\n" printf " orcli run --interactive \"file1.sh\" \"file2.sh\" - << EOF\n echo \"finished in \$SECONDS seconds\"\n EOF\n"
echo echo
fi fi
@ -711,7 +713,7 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'run\'*)' echo $' \'run\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--debug --help --memory --port -h")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port -h")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' *)' echo $' *)'
@ -847,6 +849,16 @@ orcli_run_command() {
files=() files=()
eval "files=(${args[file]})" eval "files=(${args[file]})"
# check if stdin is present if selected
if ! [[ ${args[--interactive]} ]]; then
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
if ! read -u 0 -t 0; then
orcli_run_usage
exit 1
fi
fi
fi
# update OPENREFINE_URL env # update OPENREFINE_URL env
OPENREFINE_URL="http://localhost:${args[--port]}" OPENREFINE_URL="http://localhost:${args[--port]}"
@ -889,9 +901,9 @@ orcli_run_command() {
# execute script(s) in subshell # execute script(s) in subshell
export orcli tmpdir OPENREFINE_URL openrefine_pid export orcli tmpdir OPENREFINE_URL openrefine_pid
# case 1: interactive mode if stdin is selected but not present
if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
if ! read -u 0 -t 0; then if ! read -u 0 -t 0; then
# case 1: interactive mode if stdin is selected but not present
bash --rcfile <( bash --rcfile <(
cat ~/.bashrc cat ~/.bashrc
interactive interactive
@ -899,8 +911,8 @@ orcli_run_command() {
exit exit
fi fi
fi fi
if [[ ${args[--interactive]} ]]; then
# case 2: execute scripts and keep shell running # 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 for i in "${!files[@]}"; do
@ -909,13 +921,13 @@ orcli_run_command() {
done done
interactive interactive
) -i </dev/tty ) -i </dev/tty
exit else
fi # case 3: just execute scripts
# case 3: execute scripts
for i in "${!files[@]}"; do for i in "${!files[@]}"; do
log "execute script ${files[$i]}" log "execute script ${files[$i]}"
bash -e <(awk 1 "${files[$i]}") bash -e <(awk 1 "${files[$i]}")
done done
fi
} }
@ -1525,10 +1537,10 @@ orcli_run_parse_requirements() {
;; ;;
# :flag.case # :flag.case
--debug ) --interactive )
# :flag.case_no_arg # :flag.case_no_arg
args[--debug]=1 args[--interactive]=1
shift shift
;; ;;

View File

@ -18,6 +18,7 @@ examples:
- orcli info "duplicates" - orcli info "duplicates"
- orcli export tsv "duplicates" - orcli export tsv "duplicates"
- orcli export tsv "duplicates" --output "duplicates.tsv" - orcli export tsv "duplicates" --output "duplicates.tsv"
- orcli run --interactive
- |- - |-
orcli run << EOF orcli run << EOF
orcli import csv "https://git.io/fj5hF" --projectName "duplicates" orcli import csv "https://git.io/fj5hF" --projectName "duplicates"
@ -123,9 +124,10 @@ commands:
help: PORT on which OpenRefine should listen help: PORT on which OpenRefine should listen
arg: port arg: port
default: "3333" default: "3333"
- long: --debug - long: --interactive
help: do not exit on error and keep shell open help: do not exit on error and keep bash shell open
examples: examples:
- orcli run --interactive
- |- - |-
orcli run << EOF orcli run << EOF
orcli import csv "https://git.io/fj5hF" --projectName "duplicates" orcli import csv "https://git.io/fj5hF" --projectName "duplicates"
@ -144,6 +146,6 @@ commands:
wc duplicates* wc duplicates*
EOF EOF
- |- - |-
orcli run "file1.sh" "file2.sh" - << EOF orcli run --interactive "file1.sh" "file2.sh" - << EOF
echo "finished in \$SECONDS seconds" echo "finished in \$SECONDS seconds"
EOF EOF

View File

@ -59,7 +59,7 @@ send_completions() {
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' \'run\'*)' echo $' \'run\'*)'
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--debug --help --memory --port -h")" -- "$cur" )' echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port -h")" -- "$cur" )'
echo $' ;;' echo $' ;;'
echo $'' echo $''
echo $' *)' echo $' *)'

View File

@ -4,6 +4,16 @@
files=() files=()
eval "files=(${args[file]})" eval "files=(${args[file]})"
# check if stdin is present if selected
if ! [[ ${args[--interactive]} ]]; then
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
if ! read -u 0 -t 0; then
orcli_run_usage
exit 1
fi
fi
fi
# update OPENREFINE_URL env # update OPENREFINE_URL env
OPENREFINE_URL="http://localhost:${args[--port]}" OPENREFINE_URL="http://localhost:${args[--port]}"
@ -46,9 +56,9 @@ fi
# execute script(s) in subshell # execute script(s) in subshell
export orcli tmpdir OPENREFINE_URL openrefine_pid export orcli tmpdir OPENREFINE_URL openrefine_pid
# case 1: interactive mode if stdin is selected but not present
if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
if ! read -u 0 -t 0; then if ! read -u 0 -t 0; then
# case 1: interactive mode if stdin is selected but not present
bash --rcfile <( bash --rcfile <(
cat ~/.bashrc cat ~/.bashrc
interactive interactive
@ -56,8 +66,8 @@ if [[ ${args[file]} == '-' || ${args[file]} == '"-"' ]]; then
exit exit
fi fi
fi fi
if [[ ${args[--interactive]} ]]; then
# case 2: execute scripts and keep shell running # 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 for i in "${!files[@]}"; do
@ -66,10 +76,10 @@ if [[ ${args[--debug]} ]]; then
done done
interactive interactive
) -i </dev/tty ) -i </dev/tty
exit else
fi # case 3: just execute scripts
# case 3: execute scripts
for i in "${!files[@]}"; do for i in "${!files[@]}"; do
log "execute script ${files[$i]}" log "execute script ${files[$i]}"
bash -e <(awk 1 "${files[$i]}") bash -e <(awk 1 "${files[$i]}")
done done
fi