diff options
author | Dave Reisner <dreisner@archlinux.org> | 2012-04-25 22:00:00 -0400 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-05-20 17:38:33 -0500 |
commit | ceb23622097bb59ef568fd2565d71148069664c8 (patch) | |
tree | e65b785b91deb559d94fbefeebe9e3f3f8df3968 | |
parent | 9d9c12e4e2dc92dfb6582ea7f79087e382348e71 (diff) | |
download | pacman-ceb23622097bb59ef568fd2565d71148069664c8.tar.xz |
pkgdelta: adopt parseopts for option parsing
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | scripts/Makefile.am | 3 | ||||
-rw-r--r-- | scripts/pkgdelta.sh.in | 38 |
2 files changed, 26 insertions, 15 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am index a1a4f366..ae366241 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -83,7 +83,8 @@ pacman-optimize: \ pkgdelta: \ $(srcdir)/pkgdelta.sh.in \ - $(srcdir)/library/output_format.sh + $(srcdir)/library/output_format.sh \ + $(srcdir)/library/parseopts.sh repo-add: \ $(srcdir)/repo-add.sh.in \ diff --git a/scripts/pkgdelta.sh.in b/scripts/pkgdelta.sh.in index 2fd116cb..bc79a1c0 100644 --- a/scripts/pkgdelta.sh.in +++ b/scripts/pkgdelta.sh.in @@ -40,6 +40,7 @@ max_delta_size=70 # ensure we have a sane umask set umask 0022 +m4_include(library/parseopts.sh) m4_include(library/output_format.sh) # print usage instructions @@ -155,22 +156,32 @@ create_xdelta() return 0 } -declare -a args +OPT_SHORT='hqV' +OPT_LONG=('help' 'quiet' 'max-delta-size:' 'min-pkg-size:') +if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then + exit 1 +fi +set -- "${OPTRET[@]}" +unset OPT_SHORT OPT_LONG OPTRET # parse arguments -while (( $# )); do - case "$1" in - -h|--help) usage; exit 0 ;; - -V|--version) version; exit 0 ;; - -q|--quiet) QUIET=1;; +while :; do + case $1 in + -h|--help) + usage + exit 0 ;; + -V|--version) + version + exit 0 ;; + -q|--quiet) + QUIET=1;; --min-pkg-size) if ! isnumeric "$2"; then echo "invalid argument '$2' for option -- '$1'" exit 1 fi min_pkg_size=$2 - shift - ;; + shift ;; --max-delta-size) arg=$(echo "$2" | awk '{print $1 * 100}') if ! isnumeric "$arg" || (($arg > 200)); then @@ -178,21 +189,20 @@ while (( $# )); do exit 1 fi max_delta_size=$arg + shift ;; + --) shift - ;; - --) shift; args+=("$@"); break 2 ;; - -*) echo "invalid option -- '$1'"; usage; exit 1 ;; - *) args+=("$1");; + break 2 ;; esac shift done -if (( ${#args[@]} != 2 )); then +if (( $# != 2 )); then usage exit 1 fi -for i in "${args[@]}"; do +for i in "$@"; do if [[ ! -f $i ]]; then error "$(gettext "File '%s' does not exist")" "$i" exit 1 |