mirror of https://github.com/ecmwf/eccodes.git
ECC-673: bufr_filter: Arguments not parsed correctly on CLI
This commit is contained in:
parent
cf9d512ab7
commit
8e9cecd702
|
@ -6,6 +6,7 @@ ECCODES_TOOL=codes_bufr_filter
|
||||||
result=0 # return code from function
|
result=0 # return code from function
|
||||||
ERR_TOOL_NOT_FOUND=666
|
ERR_TOOL_NOT_FOUND=666
|
||||||
|
|
||||||
|
the_tool=$ECCODES_TOOL
|
||||||
is_emoslib=0
|
is_emoslib=0
|
||||||
|
|
||||||
#########################################################
|
#########################################################
|
||||||
|
@ -15,15 +16,12 @@ is_emoslib=0
|
||||||
# sets the global variable 'result'
|
# sets the global variable 'result'
|
||||||
try_tool()
|
try_tool()
|
||||||
{
|
{
|
||||||
the_tool=$1
|
|
||||||
the_args=$args
|
|
||||||
|
|
||||||
if [ -f "${script_dir}/$the_tool" ]; then
|
if [ -f "${script_dir}/$the_tool" ]; then
|
||||||
${script_dir}/$the_tool $the_args
|
${script_dir}/$the_tool "${@}"
|
||||||
result=$?
|
result=$?
|
||||||
else
|
else
|
||||||
if command -v $the_tool >/dev/null 2>&1; then
|
if command -v $the_tool >/dev/null 2>&1; then
|
||||||
$the_tool $the_args
|
$the_tool "${@}"
|
||||||
result=$?
|
result=$?
|
||||||
else
|
else
|
||||||
#echo "Could not find $the_tool. Return error"
|
#echo "Could not find $the_tool. Return error"
|
||||||
|
@ -36,32 +34,30 @@ try_tool()
|
||||||
# Deal with case where no arguments are provided e.g. usage
|
# Deal with case where no arguments are provided e.g. usage
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
# Give priority to ecCodes over emoslib
|
# Give priority to ecCodes over emoslib
|
||||||
try_tool $ECCODES_TOOL
|
the_tool=$ECCODES_TOOL
|
||||||
|
try_tool "${@}"
|
||||||
if [ $result -eq $ERR_TOOL_NOT_FOUND ]; then
|
if [ $result -eq $ERR_TOOL_NOT_FOUND ]; then
|
||||||
try_tool $EMOSLIB_TOOL
|
the_tool=$EMOSLIB_TOOL
|
||||||
|
try_tool "${@}"
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Now process arguments. The "-i" switch is specific to emoslib
|
# Now process arguments. The "-i" switch is specific to emoslib
|
||||||
args="$@"
|
|
||||||
for i in "$@" ; do
|
for i in "$@" ; do
|
||||||
case $i in
|
if [ "$i" = "-i" ]; then is_emoslib=1; fi
|
||||||
-i) is_emoslib=1; shift ;;
|
|
||||||
*) shift ;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
|
||||||
#########################################################
|
#########################################################
|
||||||
# set -x
|
# set -x
|
||||||
if [ $is_emoslib -eq 1 ]; then
|
if [ $is_emoslib -eq 1 ]; then
|
||||||
pkg=emoslib
|
pkg=emoslib
|
||||||
tool=$EMOSLIB_TOOL
|
the_tool=$EMOSLIB_TOOL
|
||||||
try_tool $tool
|
try_tool "${@}"
|
||||||
else
|
else
|
||||||
pkg=ecCodes
|
pkg=ecCodes
|
||||||
tool=$ECCODES_TOOL
|
the_tool=$ECCODES_TOOL
|
||||||
try_tool $tool
|
try_tool "${@}"
|
||||||
fi
|
fi
|
||||||
if [ $result -eq $ERR_TOOL_NOT_FOUND ]; then
|
if [ $result -eq $ERR_TOOL_NOT_FOUND ]; then
|
||||||
echo "ERROR: Could not find the executable: $tool. Aborting!" 2>&1
|
echo "ERROR: Could not find the executable: $tool. Aborting!" 2>&1
|
||||||
|
|
Loading…
Reference in New Issue