Switch to parseopts.
Signed-off-by: Gordian Edenhofer
---
contrib/rankmirrors.sh.in | 104 +++++++++++++++++++++-------------------------
1 file changed, 48 insertions(+), 56 deletions(-)
diff --git a/contrib/rankmirrors.sh.in b/contrib/rankmirrors.sh.in
index 6ded91f..c0f2316 100644
--- a/contrib/rankmirrors.sh.in
+++ b/contrib/rankmirrors.sh.in
@@ -24,6 +24,8 @@ trap finaloutput INT
declare -r myname='rankmirrors'
declare -r myver='@PACKAGE_VERSION@'
+m4_include(../scripts/library/parseopts.sh)
+
usage() {
printf "%s (pacman) %s\n" "$myname" "$myver"
echo
@@ -43,7 +45,6 @@ provided")\n"
printf -- "$(gettext " -r, --repo <repo> Specify a repository name instead of guessing")\n"
printf -- "$(gettext " --version Show program's version number and exit")\n"
echo
- exit 0
}
version() {
@@ -122,68 +123,59 @@ finaloutput() {
exit 0
}
-
-# Argument parsing
-[[ $1 ]] || usage
-while [[ $1 ]]; do
- if [[ ${1:0:2} = -- ]]; then
- case "${1:2}" in
- help) usage ;;
- version) version ;;
- times) TIMESONLY=1 ; shift ;;
- verbose) VERBOSE=1 ; shift ;;
- url)
- CHECKURL=1;
- [[ $2 ]] || err "Must specify URL.";
- URL="$2";
- shift 2;;
- repo)
- [[ $2 ]] || err "Must specify repository name.";
- TARGETREPO="$2";
- shift 2;;
- *) err "'$1' is an invalid argument."
- esac
- elif [[ ${1:0:1} = - ]]; then
-
- if [[ ! ${1:1:1} ]]; then
- [[ -t 0 ]] && err "Stdin is empty."
- IFS=$'\n' linearray=( $(