summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-04-06 20:51:17 +0200
committerDan McGee <dan@archlinux.org>2012-04-21 00:59:57 +0200
commit70d425c1d341e5b3d36e612560f922dbd3b20e63 (patch)
tree42386adf90bf975dab53638480e3b8c7c1a1019f /scripts
parent0fc5aea027d83cc21498e14330d1f0d514a60112 (diff)
downloadpacman-70d425c1d341e5b3d36e612560f922dbd3b20e63.tar.gz
pacman-70d425c1d341e5b3d36e612560f922dbd3b20e63.tar.xz
pkgdelta: rework option/argument parser
Signed-off-by: Florian Pritz <bluewind@xinu.at> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/pkgdelta.sh.in45
1 files changed, 27 insertions, 18 deletions
diff --git a/scripts/pkgdelta.sh.in b/scripts/pkgdelta.sh.in
index 5fcc5be4..511910ba 100644
--- a/scripts/pkgdelta.sh.in
+++ b/scripts/pkgdelta.sh.in
@@ -38,11 +38,14 @@ m4_include(library/output_format.sh)
# print usage instructions
usage() {
printf "pkgdelta (pacman) %s\n\n" "$myver"
- printf -- "$(gettext "Usage: pkgdelta [-q] <package1> <package2>\n")"
+ printf -- "$(gettext "Usage: pkgdelta [options] <package1> <package2>\n")"
printf -- "$(gettext "\
pkgdelta will create a delta file between two packages.\n\
This delta file can then be added to a database using repo-add.\n\n")"
printf -- "$(gettext "Example: pkgdelta pacman-3.0.0.pkg.tar.gz pacman-3.0.1.pkg.tar.gz")\n"
+ echo
+ printf -- "$(gettext "Options:\n")"
+ printf -- " -q ""$(gettext "quiet\n")"
}
version() {
@@ -123,32 +126,38 @@ create_xdelta()
return 0
}
-case "$1" in
- -h|--help) usage; exit 0 ;;
- -V|--version) version; exit 0 ;;
- -q|--quiet) QUIET=1; shift ;;
-esac
-
-if (( $# != 2 )); then
+declare -a args
+
+# parse arguments
+while (( $# )); do
+ case "$1" in
+ -h|--help) usage; exit 0 ;;
+ -V|--version) version; exit 0 ;;
+ -q|--quiet) QUIET=1;;
+ --) shift; args+=("$@"); break 2 ;;
+ -*) echo "invalid option -- '$1'"; usage; exit 1 ;;
+ *) args+=("$1");;
+ esac
+ shift
+done
+
+if (( ${#args[@]} != 2 )); then
usage
exit 1
fi
-if [[ ! -f $1 ]]; then
- error "$(gettext "File '%s' does not exist")" "$1"
- exit 1
-fi
-
-if [[ ! -f $2 ]]; then
- error "$(gettext "File '%s' does not exist")" "$2"
- exit 1
-fi
+for i in "${args[@]}"; do
+ if [[ ! -f $i ]]; then
+ error "$(gettext "File '%s' does not exist")" "$i"
+ exit 1
+ fi
+done
if ! type xdelta3 &>/dev/null; then
error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
exit 1
fi
-create_xdelta "$1" "$2"
+create_xdelta "${args[@]}"
# vim: set ts=2 sw=2 noet: