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 export tsv \"duplicates\"\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"
echo
@ -420,8 +421,8 @@ orcli_run_usage() {
echo
# :flag.usage
echo " --debug"
printf " do not exit on error and keep shell open\n"
echo " --interactive"
printf " do not exit on error and keep bash shell open\n"
echo
# :command.usage_args
@ -435,9 +436,10 @@ orcli_run_usage() {
# :command.usage_examples
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 --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
fi
@ -711,7 +713,7 @@ send_completions() {
echo $' ;;'
echo $''
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 $' *)'
@ -847,6 +849,16 @@ orcli_run_command() {
files=()
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
OPENREFINE_URL="http://localhost:${args[--port]}"
@ -889,9 +901,9 @@ orcli_run_command() {
# execute script(s) in subshell
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 ! read -u 0 -t 0; then
# case 1: interactive mode if stdin is selected but not present
bash --rcfile <(
cat ~/.bashrc
interactive
@ -899,8 +911,8 @@ orcli_run_command() {
exit
fi
fi
if [[ ${args[--interactive]} ]]; then
# case 2: execute scripts and keep shell running
if [[ ${args[--debug]} ]]; then
bash --rcfile <(
cat ~/.bashrc
for i in "${!files[@]}"; do
@ -909,13 +921,13 @@ orcli_run_command() {
done
interactive
) -i </dev/tty
exit
fi
# case 3: execute scripts
else
# case 3: just execute scripts
for i in "${!files[@]}"; do
log "execute script ${files[$i]}"
bash -e <(awk 1 "${files[$i]}")
done
fi
}
@ -1525,10 +1537,10 @@ orcli_run_parse_requirements() {
;;
# :flag.case
--debug )
--interactive )
# :flag.case_no_arg
args[--debug]=1
args[--interactive]=1
shift
;;

View File

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

View File

@ -59,7 +59,7 @@ send_completions() {
echo $' ;;'
echo $''
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 $' *)'

View File

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