[arch-projects] [devtools][PATCH 2/6] commitpkg: use getopts to parse options

Dave Reisner d at falconindy.com
Tue Aug 16 21:35:57 EDT 2011


From: Dave Reisner <d at falconindy.com>

Signed-off-by: Dave Reisner <d at falconindy.com>
---
We shouldn't be insisting on an option order...

 commitpkg |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/commitpkg b/commitpkg
index d37babf..1275615 100755
--- a/commitpkg
+++ b/commitpkg
@@ -98,15 +98,17 @@ done
 
 # see if any limit options were passed, we'll send them to rsync
 rsyncopts=(-e ssh -p --chmod=ug=rw,o=r -c -h -L --progress --partial -y)
-if [ "$1" = '-l' ]; then
-	rsyncopts+=("--bwlimit=$2")
-	shift 2
-fi
-
-if [ "$1" = "-a" ]; then
-	commit_arch=$2
-	shift 2
-fi
+while getopts ':l:a:' flag; do
+	case $flag in
+		l) rsyncopts+=("--bwlimit=$2") ;;
+		a) commit_arch=$2 ;;
+		:) echo "option requires an argument -- '$OPTARG'" >&2
+			exit 1 ;;
+		\?) echo "invalid option -- '$OPTARG'" >&2
+			exit 1 ;;
+	esac
+done
+shift $(( OPTIND - 1 ))
 
 if [ -n "$(svn status -q)" ]; then
 	echo -n 'committing changes to trunk...'
-- 
1.7.6



More information about the arch-projects mailing list