check existence of files

This commit is contained in:
felixlohmeier 2022-11-15 23:06:41 +00:00
parent 4086797909
commit a741adf035
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