diff mbox

[xfstests-bld] util/parse_cli: use getopt to parse the options

Message ID 20180405210644.128564-1-ebiggers@google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Biggers April 5, 2018, 9:06 p.m. UTC
Use getopt to parse the options rather than the custom code that
iterates through $@.  This fixes many anomalies, such as long options
being accepted in the form '--opt ARG' but not '--opt=ARG'.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 kvm-xfstests/util/parse_cli | 69 ++++++++++++++++++++++++++++++++++---
 1 file changed, 64 insertions(+), 5 deletions(-)

Comments

Theodore Ts'o April 6, 2018, 2:13 a.m. UTC | #1
On Thu, Apr 05, 2018 at 02:06:44PM -0700, Eric Biggers wrote:
> Use getopt to parse the options rather than the custom code that
> iterates through $@.  This fixes many anomalies, such as long options
> being accepted in the form '--opt ARG' but not '--opt=ARG'.

getopt is in util-linux, which implies that if there is anyone trying
to launch gce-xfstests from MacOS, it won't work any more with this
commit.  I don't *think* this is a problem, and if so a workaround is
to use Cloud Shell[1], but if this change will break anyone, please
speak now....

						- Ted
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/kvm-xfstests/util/parse_cli b/kvm-xfstests/util/parse_cli
index 52f518a..7043ab1 100644
--- a/kvm-xfstests/util/parse_cli
+++ b/kvm-xfstests/util/parse_cli
@@ -155,8 +155,56 @@  validate_config_name()
     fi
 }
 
-while [ "$1" != "" ]; do
-    case $1 in
+shortopts="ac:C:g:hI:m:n:No:O:r:vx:X:"
+longopts=(
+aio:
+archive
+bucket-subdir:
+cache:
+email:
+gce-zone:
+gs-bucket:
+help
+hooks:
+image-project:
+initrd:
+instance-name:
+kernel:
+local-ssd
+log
+machtype:
+no-action
+no-archive
+no-collapse
+no-email
+no-insert
+no-log
+no-preemptible
+no-punch
+no-region-shard
+no-virtio-rng
+no-zero
+numa:
+pmem-device
+preemptible
+testrunid:
+update-files
+update-xfstests
+update-xfstests-tar
+virtfs-model:
+virtfs-scratch:
+virtfs-test:
+virtfs:
+)
+longopts=$(echo "${longopts[*]}" | tr ' ' ,)
+
+if ! options=$(getopt -o "$shortopts" -l "$longopts" -- "$@"); then
+    print_help
+fi
+
+eval set -- "$options"
+while (( $# >= 1 )); do
+    case "$1" in
 	-a)
 	    DO_AEX=""
 	    ;;
@@ -419,6 +467,20 @@  while [ "$1" != "" ]; do
 	    supported_flavors kvm
 	    unset DO_ARCHIVE
 	    ;;
+	--)
+	    shift
+	    break
+	    ;;
+	*)
+	    echo 1>&2 "Invalid option: \"$1\""
+	    print_help
+	    ;;
+    esac
+    shift
+done
+
+while (( $# >= 1 )); do
+    case "$1" in
 	smoke)
 	    if test -n "$FSTESTCFG" ; then
 		echo "You can use either '-c' or 'smoke', not both! " \
@@ -459,9 +521,6 @@  while [ "$1" != "" ]; do
 	ver)
 	    ARG="cmd=ver"
 	    ;;
-	-*)
-	    print_help
-	    ;;
 	*)
 	    validate_test_name "$1"
 	    FSTESTSET="$FSTESTSET,$1"