Compare commits

...

1 Commits

Author SHA1 Message Date
Levente Polyak
3c1229479c commitpkg: handle option parsind and help before abort checks
Previously it was not possible to call for the help of find early
command line option problems when invoking in any location on the shell
as the command aborted without PKGBUILD being present.

Fix this by moving everything related to options at the very top.
2022-08-23 20:41:49 +02:00

View File

@@ -22,16 +22,8 @@ elif [[ -r "$HOME/.makepkg.conf" ]]; then
fi
cmd=${0##*/}
if [[ ! -f PKGBUILD ]]; then
die 'No PKGBUILD file'
fi
source=()
# shellcheck source=contrib/makepkg/PKGBUILD.proto
. ./PKGBUILD
pkgbase=${pkgbase:-$pkgname}
rsyncopts=(-e ssh -p '--chmod=ug=rw,o=r' -c -h -L --progress --partial -y)
archreleaseopts=()
case "$cmd" in
commitpkg)
if (( $# == 0 )); then
@@ -47,7 +39,26 @@ case "$cmd" in
die 'Usage: commitpkg <reponame> [-f] [-s server] [-l limit] [-a arch] [commit message]'
;;
esac
while getopts ':l:a:s:f' flag; do
case $flag in
f) archreleaseopts+=('-f') ;;
s) server=$OPTARG ;;
l) rsyncopts+=("--bwlimit=$OPTARG") ;;
a) commit_arch=$OPTARG ;;
:) die "Option requires an argument -- '%s'" "$OPTARG" ;;
\?) die "Invalid option -- '%s'" "$OPTARG" ;;
esac
done
shift $(( OPTIND - 1 ))
if [[ ! -f PKGBUILD ]]; then
die 'No PKGBUILD file'
fi
source=()
# shellcheck source=contrib/makepkg/PKGBUILD.proto
. ./PKGBUILD
pkgbase=${pkgbase:-$pkgname}
if (( ${#validpgpkeys[@]} != 0 )); then
if [[ -d keys ]]; then
@@ -88,20 +99,6 @@ if (( ${#needsversioning[*]} )); then
(( ${#unversioned[*]} )) && die "%s is not under version control" "${unversioned[@]}"
fi
rsyncopts=(-e ssh -p '--chmod=ug=rw,o=r' -c -h -L --progress --partial -y)
archreleaseopts=()
while getopts ':l:a:s:f' flag; do
case $flag in
f) archreleaseopts+=('-f') ;;
s) server=$OPTARG ;;
l) rsyncopts+=("--bwlimit=$OPTARG") ;;
a) commit_arch=$OPTARG ;;
:) die "Option requires an argument -- '%s'" "$OPTARG" ;;
\?) die "Invalid option -- '%s'" "$OPTARG" ;;
esac
done
shift $(( OPTIND - 1 ))
# check packages for validity
for _arch in "${arch[@]}"; do
if [[ -n $commit_arch && ${_arch} != "$commit_arch" ]]; then