update: improve help.

This commit corrects linelength (this should have no functional impact)
and adds exit codes

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Acked-by: Adrien 'neox' Bourmault <neox@gnu.org>
neox: wrote the commit message
This commit is contained in:
Denis 'GNUtoo' Carikli 2023-11-27 13:48:56 +01:00 committed by Adrien 'neox' Bourmault
parent a945fa8e15
commit c410023ea3
Signed by: neox
GPG Key ID: 2974E1D5F25DFCC8
1 changed files with 20 additions and 8 deletions

28
update
View File

@ -26,6 +26,8 @@ set -u -e
projectname="$(cat projectname)" projectname="$(cat projectname)"
./resources/scripts/misc/versioncheck ./resources/scripts/misc/versioncheck
. resources/scripts/misc/sysexits.sh
list_packages() { list_packages() {
ls -d resources/packages/*/update/ | \ ls -d resources/packages/*/update/ | \
sed 's#resources/packages/##' | \ sed 's#resources/packages/##' | \
@ -41,7 +43,9 @@ listoptions() {
help() { help() {
cat <<- EOF cat <<- EOF
USAGE: ./update <PACKAGE> <OPTION> Usage:
./update <PACKAGE> <OPTION>
./update --help
possible values for 'package': possible values for 'package':
$(list_packages) $(list_packages)
@ -54,17 +58,21 @@ help() {
} }
die() { die() {
ret="$1"
shift 1
printf 'Error: %s\n' "${@}" 1>&2 printf 'Error: %s\n' "${@}" 1>&2
exit 1 exit "${ret}"
} }
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
die "Wrong number of arguments specified. See './update help'." die "${EX_USAGE}" \
"Wrong number of arguments specified. See './update --help'."
fi fi
package="${1}" package="${1}"
[ "${package}" = help ] && help && exit 0 [ "${package}" = "--help" ] && help && exit 0
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
option="${2}" option="${2}"
@ -73,8 +81,9 @@ if [ $# -gt 1 ]; then
case "${option}" in case "${option}" in
list) list)
if [ ! -d resources/packages/"${package}" ] ; then if [ ! -d resources/packages/"${package}" ] ; then
die "Invalid package '${package}'." \ die "${EX_USAGE}" \
" See './update help'." "Invalid package '${package}'." \
" See './update --help'."
else else
printf "Available options for package '%s':\n\n" \ printf "Available options for package '%s':\n\n" \
"${package}" "${package}"
@ -92,12 +101,15 @@ if [ $# -gt 1 ]; then
"${pkg_dir}"/update/"${option}" $@ "${pkg_dir}"/update/"${option}" $@
else else
help help
die "Invalid option for '${package}'." \ die "${EX_USAGE}" \
"Invalid option for '${package}'." \
" See './update ${package} list'." " See './update ${package} list'."
fi fi
else else
help help
die "Invalid package '${package}'. See './update help'." die "${EX_USAGE}" \
"Invalid package '${package}'." \
" See './update --help'."
fi fi
esac esac
else else