build.sh: improve command line parsing
The previous code was simple and worked but it didn't scale. With one --with-*-path argument, we have only one elif clause. With 2 --with-*-path arguments we end up with 4 elif clauses. And with 3 --with-*-path arguments we end up with 13 elif clauses which is way too much. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> Acked-by: Adrien 'neox' Bourmault <neox@a-lec.org>
This commit is contained in:
parent
e4fe5e0e56
commit
eb5845b8b1
56
build.sh
56
build.sh
|
@ -61,25 +61,45 @@ sync_repo()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $# -eq 1 ] && [ "$1" = "-h" -o "$1" == "--help" ] ; then
|
help_missing_arg()
|
||||||
|
{
|
||||||
|
printf "Error: Argument of %s is missing.\n\n" "$1"
|
||||||
help
|
help
|
||||||
exit 0
|
}
|
||||||
elif [ $# -eq 2 ] && [ "$1" = "--with-lbwww-path" ] ; then
|
|
||||||
lbwww_path="$(realpath $2)"
|
i=1
|
||||||
elif [ $# -eq 2 ] && [ "$1" = "--with-lbwww-img-path" ] ; then
|
while [ $i -le $# ] ; do
|
||||||
lbwww_img_path="$(realpath $2)"
|
opt="$(eval echo \$$i)"
|
||||||
elif [ $# -eq 4 ] && [ "$1" = "--with-lbwww-path" ] && \
|
|
||||||
[ "$3" = "--with-lbwww-img-path" ] ; then
|
case "${opt}" in
|
||||||
lbwww_path="$(realpath $2)"
|
-h|--help)
|
||||||
lbwww_img_path="$(realpath $4)"
|
help
|
||||||
elif [ $# -eq 4 ] && [ "$1" = "--with-lbwww-img-path" ] && \
|
exit 0
|
||||||
[ "$3" = "--with-lbwww-path" ] ; then
|
;;
|
||||||
lbwww_img_path="$(realpath $2)"
|
--with-lbwww-path)
|
||||||
lbwww_path="$(realpath $4)"
|
if [ $i -ge $# ] ; then
|
||||||
elif [ $# -ne 0 ] ; then
|
help_missing_arg "--with-lbwww-path"
|
||||||
help
|
exit ${EX_USAGE}
|
||||||
exit ${EX_USAGE}
|
fi
|
||||||
fi
|
lbwww_path="$(eval echo \$$(expr $i + 1))"
|
||||||
|
i="$(expr $i + 1)"
|
||||||
|
;;
|
||||||
|
--with-lbwww-img-path)
|
||||||
|
if [ $i -ge $# ] ; then
|
||||||
|
help_missing_arg "--with-lbwww-img-path"
|
||||||
|
exit ${EX_USAGE}
|
||||||
|
fi
|
||||||
|
lbwww_img_path="$(eval echo \$$(expr $i + 1))"
|
||||||
|
i="$(expr $i + 1)"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
help
|
||||||
|
exit ${EX_USAGE}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
i="$(expr $i + 1)"
|
||||||
|
done
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue