Merge pull request #80 from opencultureconsulting:felixlohmeier/run-error-handling-76
check existence of files
This commit is contained in:
commit
46e181f8af
30
orcli
30
orcli
|
@ -638,7 +638,7 @@ function init_import() {
|
||||||
data+=("project-file=@-")
|
data+=("project-file=@-")
|
||||||
else
|
else
|
||||||
if ! path=$(readlink -e "${file}"); then
|
if ! path=$(readlink -e "${file}"); then
|
||||||
error "file ${file} not found!"
|
error "cannot open ${file} (no such file)!"
|
||||||
fi
|
fi
|
||||||
data+=("project-file=@${path}")
|
data+=("project-file=@${path}")
|
||||||
fi
|
fi
|
||||||
|
@ -899,6 +899,22 @@ orcli_transform_command() {
|
||||||
fi
|
fi
|
||||||
done
|
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
|
# support multiple files
|
||||||
for i in "${!files[@]}"; do
|
for i in "${!files[@]}"; do
|
||||||
# read each operation into one line
|
# read each operation into one line
|
||||||
|
@ -1009,15 +1025,23 @@ orcli_run_command() {
|
||||||
files=()
|
files=()
|
||||||
eval "files=(${args[file]})"
|
eval "files=(${args[file]})"
|
||||||
|
|
||||||
# check if stdin is present if selected
|
# 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 ! [[ ${args[--interactive]} ]]; then
|
||||||
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
|
|
||||||
if ! read -u 0 -t 0; then
|
if ! read -u 0 -t 0; then
|
||||||
orcli_run_usage
|
orcli_run_usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
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
|
# assume that quiet flag shall suppress log output generally in batch mode
|
||||||
if [[ ${args[--quiet]} ]]; then
|
if [[ ${args[--quiet]} ]]; then
|
||||||
|
|
|
@ -40,7 +40,7 @@ function init_import() {
|
||||||
data+=("project-file=@-")
|
data+=("project-file=@-")
|
||||||
else
|
else
|
||||||
if ! path=$(readlink -e "${file}"); then
|
if ! path=$(readlink -e "${file}"); then
|
||||||
error "file ${file} not found!"
|
error "cannot open ${file} (no such file)!"
|
||||||
fi
|
fi
|
||||||
data+=("project-file=@${path}")
|
data+=("project-file=@${path}")
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -4,15 +4,23 @@
|
||||||
files=()
|
files=()
|
||||||
eval "files=(${args[file]})"
|
eval "files=(${args[file]})"
|
||||||
|
|
||||||
# check if stdin is present if selected
|
# 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 ! [[ ${args[--interactive]} ]]; then
|
||||||
if [[ ${args[file]} == '-' ]] || [[ ${args[file]} == '"-"' ]]; then
|
|
||||||
if ! read -u 0 -t 0; then
|
if ! read -u 0 -t 0; then
|
||||||
orcli_run_usage
|
orcli_run_usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
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
|
# assume that quiet flag shall suppress log output generally in batch mode
|
||||||
if [[ ${args[--quiet]} ]]; then
|
if [[ ${args[--quiet]} ]]; then
|
||||||
|
|
|
@ -26,6 +26,22 @@ for i in "${!files[@]}"; do
|
||||||
fi
|
fi
|
||||||
done
|
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
|
# support multiple files
|
||||||
for i in "${!files[@]}"; do
|
for i in "${!files[@]}"; do
|
||||||
# read each operation into one line
|
# read each operation into one line
|
||||||
|
|
Loading…
Reference in New Issue