summaryrefslogtreecommitdiff
path: root/apkgrel.in
diff options
context:
space:
mode:
Diffstat (limited to 'apkgrel.in')
-rw-r--r--apkgrel.in61
1 files changed, 35 insertions, 26 deletions
diff --git a/apkgrel.in b/apkgrel.in
index 46e189f..57b3b93 100644
--- a/apkgrel.in
+++ b/apkgrel.in
@@ -55,42 +55,51 @@ do_nothing() {
return 0
}
-do_usage() {
- cat <<__EOF__
-Usage: $prog -a|-h|-s NUM|-t|-z [-f] FILE...
-Commands:
- -a Add 1 to current pkgrel
- -g Only do the change on files that have clean git status
- -h Show this help
- -s Set pkgrel to NUM
- -t Only verify that files are in proper format
- -z Set pkgrel to 0
-
+usage() {
+ cat >&2 <<__EOF__
+$prog $abuild_ver - display or bump pkgrel in APKBUILDs
+Usage: $prog [-z|--zero] [-a|--add] [-g|--clean-git] [-s|--set NUM] [-t|--test] [-f|--force] DIR or APKBUILD...
Options:
- -f Force, even if given files are not in proper format
+ -z, --zero Set pkgrel to 0
+ -a, --add Add 1 to current pkgrel
+ -g, --clean-git Only operate on APKBUILDs with clean git status
+ -s, --set NUM Set pkgrel to NUM
+ -t, --test Only verify that files have a valid pkgrel
+ -f, --force Operate on files without a valid pkgrel
+ -h, --help Show this help
__EOF__
}
cmd=do_show
force=
-while getopts "afghs:tz" opt; do
- case $opt in
- a) cmd=do_add;;
- g) only_clean_git=1;;
- f) force=1;;
- h) cmd=do_usage;;
- s) setto=$OPTARG; cmd=do_set;;
- t) cmd=do_nothing;;
- z) setto=0; cmd=do_set;;
+setto=
+only_clean_git=
+
+args=`getopt -o zags:tfqh --long zero,add,clean-git,set:,test,force,quiet,help -n "$prog" -- "$@"`
+if [ $? -ne 0 ]; then
+ usage
+ exit 2
+fi
+eval set -- "$args"
+while true; do
+ case $1 in
+ -z|--zero) setto=0; cmd=do_set;;
+ -a|--add) cmd=do_add;;
+ -g|--clean-git) only_clean_git=1;;
+ -s|--set) setto=$2; shift; cmd=do_set;;
+ -t|--test) cmd=do_nothing;;
+ -f|--force) force=1;;
+ -q|--quiet) quiet=1;; # noop
+ -h|--help) usage; exit;;
+ --) shift; break;;
+ *) exit 1;; # getopt error
esac
+ shift
done
-
-shift $(( $OPTIND - 1))
-
if [ $# -eq 0 ]; then
- do_usage
- exit 1
+ usage
+ exit 2
fi
do_verify "$@" || exit 1