mirror of
https://github.com/limosek/zaf.git
synced 2025-11-01 01:57:38 +01:00
Added return parameters checking
This commit is contained in:
52
lib/zafret
Executable file
52
lib/zafret
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/bin/sh
|
||||
|
||||
. $(dirname $0)/preload.sh
|
||||
|
||||
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
|
||||
zaf_err "zafret valuefile stderrfile retcode [return return_if_null return_if_error]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
value="$(cat $1)"
|
||||
rm -f $1
|
||||
shift
|
||||
|
||||
stderr="$(cat $1)"
|
||||
rm -f $1
|
||||
shift
|
||||
|
||||
retcode="$1"
|
||||
shift
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
ret="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
retnull="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
reterr="$1"
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ "$retcode" != 0 ]; then
|
||||
echo "$reterr"
|
||||
zaf_wrn "${ITEM_KEY}("$*"): Error code '$retcode', returning '$reterr' ($stderr)"
|
||||
exit $retcode
|
||||
fi
|
||||
|
||||
if [ -z "$value" ]; then
|
||||
echo "$retnull"
|
||||
zaf_wrn "${ITEM_KEY}("$*"): Got empty result, returning '$retnull' ($stderr)"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo $value
|
||||
if [ -n "$stderr" ]; then
|
||||
zaf_wrn "${ITEM_KEY}("$*"): $stderr"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user