public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@google.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: fstests@vger.kernel.org, Eric Biggers <ebiggers@google.com>
Subject: [xfstests-bld PATCH] util/parse_cli: use getopt to parse the options
Date: Thu,  5 Apr 2018 14:06:44 -0700	[thread overview]
Message-ID: <20180405210644.128564-1-ebiggers@google.com> (raw)

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(-)

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"
-- 
2.17.0.484.g0c8726318c-goog


             reply	other threads:[~2018-04-05 21:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-05 21:06 Eric Biggers [this message]
2018-04-06  2:13 ` [xfstests-bld PATCH] util/parse_cli: use getopt to parse the options Theodore Y. Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180405210644.128564-1-ebiggers@google.com \
    --to=ebiggers@google.com \
    --cc=fstests@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox