Merge pull request #80 from opencultureconsulting:felixlohmeier/run-error-handling-76

check existence of files
This commit is contained in:
Felix Lohmeier 2022-11-16 00:07:21 +01:00 committed by GitHub
commit 46e181f8af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 16 deletions

40
orcli
View File

@ -638,7 +638,7 @@ function init_import() {
data+=("project-file=@-")
else
if ! path=$(readlink -e "${file}"); then
error "file ${file} not found!"
error "cannot open ${file} (no such file)!"
fi
data+=("project-file=@${path}")
fi
@ -899,6 +899,22 @@ orcli_transform_command() {
fi
done
# check existence of files and stdin
for i in "${!files[@]}"; do
if [[ "${files[$i]}" == '-' ]] || [[ "${files[$i]}" == '"-"' ]]; then
# exit if stdin is selected but not present
if ! read -u 0 -t 0; then
orcli_transform_usage
exit 1
fi
else
# exit if file does not exist
if ! [[ -f "${files[$i]}" ]]; then
error "cannot open ${files[$i]} (no such file)!"
fi
fi
done
# support multiple files
for i in "${!files[@]}"; do
# read each operation into one line
@ -1009,15 +1025,23 @@ 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
# check existence of files and stdin
for i in "${!files[@]}"; do
if [[ "${files[$i]}" == '-' ]] || [[ "${files[$i]}" == '"-"' ]]; then
# exit if stdin is selected but not present
if ! [[ ${args[--interactive]} ]]; then
if ! read -u 0 -t 0; then
orcli_run_usage
exit 1
fi
fi
else
# exit if file does not exist
if ! [[ -f "${files[$i]}" ]]; then
error "cannot open ${files[$i]} (no such file)!"
fi
fi
fi
done
# assume that quiet flag shall suppress log output generally in batch mode
if [[ ${args[--quiet]} ]]; then

View File

@ -40,7 +40,7 @@ function init_import() {
data+=("project-file=@-")
else
if ! path=$(readlink -e "${file}"); then
error "file ${file} not found!"
error "cannot open ${file} (no such file)!"
fi
data+=("project-file=@${path}")
fi

View File

@ -4,15 +4,23 @@
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
# check existence of files and stdin
for i in "${!files[@]}"; do
if [[ "${files[$i]}" == '-' ]] || [[ "${files[$i]}" == '"-"' ]]; then
# exit if stdin is selected but not present
if ! [[ ${args[--interactive]} ]]; then
if ! read -u 0 -t 0; then
orcli_run_usage
exit 1
fi
fi
else
# exit if file does not exist
if ! [[ -f "${files[$i]}" ]]; then
error "cannot open ${files[$i]} (no such file)!"
fi
fi
fi
done
# assume that quiet flag shall suppress log output generally in batch mode
if [[ ${args[--quiet]} ]]; then

View File

@ -26,6 +26,22 @@ for i in "${!files[@]}"; do
fi
done
# check existence of files and stdin
for i in "${!files[@]}"; do
if [[ "${files[$i]}" == '-' ]] || [[ "${files[$i]}" == '"-"' ]]; then
# exit if stdin is selected but not present
if ! read -u 0 -t 0; then
orcli_transform_usage
exit 1
fi
else
# exit if file does not exist
if ! [[ -f "${files[$i]}" ]]; then
error "cannot open ${files[$i]} (no such file)!"
fi
fi
done
# support multiple files
for i in "${!files[@]}"; do
# read each operation into one line