[pacman-dev] [PATCH 04/11] pacdiff: proper option handling
Gordian Edenhofer
gordian.edenhofer at gmail.com
Thu Sep 29 10:23:04 UTC 2016
Switch to parseopts.
Signed-off-by: Gordian Edenhofer <gordian.edenhofer at gmail.com>
---
contrib/pacdiff.sh.in | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index 840e36f..bed9ea3 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -30,6 +30,7 @@ declare -a oldsaves
declare -i USE_FIND=0 USE_LOCATE=0 USE_PACDB=0 OUTPUTONLY=0
m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/parseopts.sh)
usage() {
printf "%s (pacman) %s\n" "$myname" "$myver"
@@ -94,7 +95,17 @@ cmd() {
fi
}
-while [[ -n "$1" ]]; do
+# Parse arguments
+OPT_SHORT='lfpoVh'
+OPT_LONG=('locate' 'find' 'pacmandb' 'output' 'nocolor' 'version' 'help')
+if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
+ usage
+ exit 1
+fi
+set -- "${OPTRET[@]}"
+unset OPT_SHORT OPT_LONG OPTRET
+
+while :; do
case "$1" in
-l|--locate)
USE_LOCATE=1;;
@@ -107,11 +118,14 @@ while [[ -n "$1" ]]; do
--nocolor)
USE_COLOR='n';;
-V|--version)
- version; exit 0;;
+ version
+ exit 0;;
-h|--help)
- usage; exit 0;;
- *)
- usage; exit 1;;
+ usage
+ exit 0;;
+ --)
+ shift
+ break 2;;
esac
shift
done
--
2.10.0
More information about the pacman-dev
mailing list