modify: 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:46:08 +01:00 committed by Adrien 'neox' Bourmault
parent 57050c2985
commit a945fa8e15
Signed by: neox
GPG Key ID: 2974E1D5F25DFCC8
1 changed files with 20 additions and 7 deletions

27
modify
View File

@ -24,6 +24,9 @@
set -u -e set -u -e
projectname="$(cat projectname)" projectname="$(cat projectname)"
. resources/scripts/misc/sysexits.sh
./resources/scripts/misc/versioncheck ./resources/scripts/misc/versioncheck
list_modify_paths() { list_modify_paths() {
@ -33,6 +36,7 @@ list_modify_paths() {
-name "modify" \ -name "modify" \
-printf "%P\n" -printf "%P\n"
} }
list_packages() { list_packages() {
list_modify_paths | \ list_modify_paths | \
sed 's#/.*##' sed 's#/.*##'
@ -49,7 +53,9 @@ listoptions() {
help() { help() {
cat <<- EOF cat <<- EOF
USAGE: ./modify <PACKAGE> <OPTION> Usage:
./modify <PACKAGE> <OPTION>
./modify --help
possible values for 'package': possible values for 'package':
$(list_packages) $(list_packages)
@ -62,17 +68,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 './modify help'." die "${EX_USAGE}" \
"Wrong number of arguments specified. See './modify --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
@ -82,7 +92,8 @@ 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}" \
"Invalid package '${package}'." \
" See './modify help'." " See './modify help'."
else else
printf "Available options for package '%s':\n\n" \ printf "Available options for package '%s':\n\n" \
@ -102,12 +113,14 @@ if [ $# -gt 1 ]; then
"${pkg_dir}"/modify/"${option}" $@ "${pkg_dir}"/modify/"${option}" $@
else else
help help
die "Invalid option for '${package}'." \ die "${EX_USAGE}" \
"Invalid option for '${package}'." \
" See './modify ${package} list'." " See './modify ${package} list'."
fi fi
else else
help help
die "Invalid package '${package}'. See './modify help'." die "${EX_USAGE}" \
"Invalid package '${package}'. See './modify help'."
fi fi
esac esac
else else