Commit 6c8da0c69eacfa9be3899f93eb7b1e78bd5533f1

Christian Weisgerber 2020-10-03T19:14:53

rewrite argument parsing with the POSIX getopts shell built-in ok stsp

diff --git a/regress/cmdline/common.sh b/regress/cmdline/common.sh
index d982671..9c91480 100644
--- a/regress/cmdline/common.sh
+++ b/regress/cmdline/common.sh
@@ -200,26 +200,20 @@ test_cleanup()
 
 test_parseargs()
 {
-	args=`getopt qr: $*`
-	if [ $? -ne 0 ]; then
-		echo "Supported options:"
-		echo "  -q: quiet mode"
-		echo "  -r PATH: use PATH as test data root directory"
-		exit 2
-	fi
-	set -- $args
-	while [ $# -ne 0 ]; do
-		case "$1"
-		in
-			-q)
-			   export GOT_TEST_QUIET=1; shift;;
-			-r)
-			   export GOT_TEST_ROOT="$2"; shift; shift;;
-			--)
-			   shift; break;;
+	while getopts qr: flag; do
+		case $flag in
+		q)	export GOT_TEST_QUIET=1
+			;;
+		r)	export GOT_TEST_ROOT=$OPTARG
+			;;
+		?)	echo "Supported options:"
+			echo "  -q: quiet mode"
+			echo "  -r PATH: use PATH as test data root directory"
+			exit 2
+			;;
 		esac
 	done
-}
+} >&2
 
 run_test()
 {