mirror of
https://gitlab.alpinelinux.org/alpine/abuild.git
synced 2024-12-24 16:02:23 +00:00
newapkbuild: check arguments and improve usage()
Changes: * argument sanity checks: * `PKGNAME[-PKGVER] | SRCURL` * check if missing * check if specified more than once (see below) * specifying more than one buildtype flag * `-n` (set pkgname) without using SRCURL as last argument * `-s` (sourceforge source) without using PKGNAME as last argument * Typo fix: exist -> exists * `usage()`: * always print PKGNAME and PKGDESC (instead of NAME and DESC, NAME was used in one place and PKGNAME in another) * link to <https://spdx.org/licenses/> * `-m` (meson) flag was missing in short usage line at the top * indicate that the buildtypes are exclusive * `-c` flag: remove "to new directory" wording to make the message shorter (this should be obvious) * remove empty line at the end NOTE: Before this commit, the `PKGNAME[-PKGVER] | SRCURL` was allowed to be specified more than once, and the code looped over the arguments. But this was not documented in `usage()` and had unexpected results: ``` $ newapkbuild first second third $ tree . ___ first ___ APKBUILD ___ first ___ ___ APKBUILD ___ ___ first ___ ___ ___ APKBUILD ___ ___ ___ src ___ ___ src ___ src ```
This commit is contained in:
parent
0bb0bd8498
commit
a68354ebc5
@ -344,13 +344,14 @@ __EOF__
|
|||||||
usage() {
|
usage() {
|
||||||
cat >&2 <<-__EOF__
|
cat >&2 <<-__EOF__
|
||||||
$program $program_version - generate a new APKBUILD
|
$program $program_version - generate a new APKBUILD
|
||||||
Usage: $program [-n NAME] [-d DESC] [-l LICENSE] [-u URL]
|
Usage: $program [-n PKGNAME] [-d PKGDESC] [-l LICENSE] [-u URL]
|
||||||
[-aCpy] [-s] [-cfh]
|
[-a | -C | -m | -p | -y] [-s] [-c] [-f] [-h]
|
||||||
PKGNAME[-PKGVER]|SRCURL
|
PKGNAME[-PKGVER] | SRCURL
|
||||||
Options:
|
Options:
|
||||||
-n Set package name to NAME
|
-n Set package name to PKGNAME (only use with SRCURL)
|
||||||
-d Set package description (pkgdesc) to DESC
|
-d Set package description to PKGDESC
|
||||||
-l Set package license to LICENSE
|
-l Set package license to LICENSE, use identifiers from:
|
||||||
|
<https://spdx.org/licenses/>
|
||||||
-u Set package URL
|
-u Set package URL
|
||||||
-a Create autotools package (use ./configure ...)
|
-a Create autotools package (use ./configure ...)
|
||||||
-C Create CMake package (Assume cmake/ is there)
|
-C Create CMake package (Assume cmake/ is there)
|
||||||
@ -358,33 +359,58 @@ usage() {
|
|||||||
-p Create perl package (Assume Makefile.PL is there)
|
-p Create perl package (Assume Makefile.PL is there)
|
||||||
-y Create python package (Assume setup.py is there)
|
-y Create python package (Assume setup.py is there)
|
||||||
-s Use sourceforge source URL
|
-s Use sourceforge source URL
|
||||||
-c Copy a sample init.d, conf.d, and install script to new directory
|
-c Copy a sample init.d, conf.d, and install script
|
||||||
-f Force even if directory already exist
|
-f Force even if directory already exists
|
||||||
-h Show this help
|
-h Show this help
|
||||||
|
|
||||||
__EOF__
|
__EOF__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_buildtype() {
|
||||||
|
if [ -n "$buildtype" ]; then
|
||||||
|
error "More than one buildtype flag specified ($buildtype and $1)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
buildtype="$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_arguments() {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
error "Missing required argument: PKGNAME[-PKGVER] | SRCURL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ $# -gt 1 ]; then
|
||||||
|
shift
|
||||||
|
error "Unrecognized arguments: $*"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! is_url "$1" && [ -n "$pkgname" ]; then
|
||||||
|
error "-n is only allowed when using SRCURL as last argument"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if is_url "$1" && [ -n "$sourceforge" ]; then
|
||||||
|
error "-s is only allowed when using PKGNAME as last argument"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
while getopts "acCmd:fhl:n:pyu:s" opt; do
|
while getopts "acCmd:fhl:n:pyu:s" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
'a') buildtype="autotools";;
|
'a') set_buildtype "autotools";;
|
||||||
'c') cpinitd=1;;
|
'c') cpinitd=1;;
|
||||||
'C') buildtype="cmake";;
|
'C') set_buildtype "cmake";;
|
||||||
'm') buildtype="meson";;
|
'm') set_buildtype "meson";;
|
||||||
'd') pkgdesc="$OPTARG";;
|
'd') pkgdesc="$OPTARG";;
|
||||||
'f') force=1;;
|
'f') force=1;;
|
||||||
'h') usage; exit;;
|
'h') usage; exit;;
|
||||||
'l') license="$OPTARG";;
|
'l') license="$OPTARG";;
|
||||||
'n') pkgname="$OPTARG";;
|
'n') pkgname="$OPTARG";;
|
||||||
'p') buildtype="perl";;
|
'p') set_buildtype "perl";;
|
||||||
'y') buildtype="python";;
|
'y') set_buildtype "python";;
|
||||||
'u') url="$OPTARG";;
|
'u') url="$OPTARG";;
|
||||||
's') sourceforge=1;;
|
's') sourceforge=1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $(( $OPTIND - 1 ))
|
shift $(( $OPTIND - 1 ))
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
check_arguments "$@"
|
||||||
newaport $1 || exit 1
|
newaport $1
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
Loading…
Reference in New Issue
Block a user