stagefiles: refactor Require_stagefile()
- count of params is available as $#, we don't need the pipe-to-wc logic. - the whole 'CONTINUE' based logic is silly, we can just return once one of the files is found. - setting of 'NAME' in the loop was completely pointless. - the error message for multiple files was not very clear just injecting a sequence of words into a sentence. - it did not work correctly if no arguments were given (bad usage) note, you might question whether the functionality of this function is correct, as did I; this is tackled in a followup commit whilst this commit retains the existing functionality! Gbp-Dch: Short
This commit is contained in:
parent
dadeec9d39
commit
1b09b15277
|
@ -63,37 +63,28 @@ Remove_stagefile ()
|
|||
rm -f "${FILE}"
|
||||
}
|
||||
|
||||
# Find at least one of the required stages, `exit 1` if none found
|
||||
Require_stagefile ()
|
||||
{
|
||||
local NAME
|
||||
local FILES
|
||||
local NUMBER
|
||||
NAME="$(basename ${0})"
|
||||
FILES="${@}" #must be on separate line to 'local' declaration to avoid error
|
||||
NUMBER="$(echo ${@} | wc -w)"
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
Echo_warning "Bad `Require_stagefile` usage, no params were supplied"
|
||||
return 0
|
||||
fi
|
||||
local FILE
|
||||
local CONTINUE=false
|
||||
for FILE in ${FILES}
|
||||
do
|
||||
FILE=".build/${FILE}"
|
||||
# Find at least one of the required stages
|
||||
if [ -f ${FILE} ]
|
||||
then
|
||||
CONTINUE=true
|
||||
NAME="${NAME} $(basename ${FILE})"
|
||||
for FILE in ${@}; do
|
||||
if [ -f ".build/${FILE}" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
if ! $CONTINUE
|
||||
then
|
||||
if [ "${NUMBER}" -eq 1 ]
|
||||
then
|
||||
Echo_error "%s: %s missing" "${NAME}" "${FILE}"
|
||||
else
|
||||
Echo_error "%s: one of %s is missing" "${NAME}" "${FILES}"
|
||||
fi
|
||||
local NAME
|
||||
NAME="$(basename ${0})"
|
||||
|
||||
exit 1
|
||||
if [ $# -eq 1 ]; then
|
||||
Echo_error "%s requires stage: %s" "${NAME}" "${FILE}"
|
||||
else
|
||||
Echo_error "%s requires one of these stages: %s" "${NAME}" "$(echo ${@})"
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue