All of lore.kernel.org
 help / color / mirror / Atom feed
* [xfstests-bld PATCH] util/parse_cli: use getopt to parse the options
@ 2018-04-05 21:06 Eric Biggers
  2018-04-06  2:13 ` Theodore Y. Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2018-04-05 21:06 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: fstests, Eric Biggers

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [xfstests-bld PATCH] util/parse_cli: use getopt to parse the options
  2018-04-05 21:06 [xfstests-bld PATCH] util/parse_cli: use getopt to parse the options Eric Biggers
@ 2018-04-06  2:13 ` Theodore Y. Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Y. Ts'o @ 2018-04-06  2:13 UTC (permalink / raw)
  To: Eric Biggers; +Cc: fstests

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-06  2:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-05 21:06 [xfstests-bld PATCH] util/parse_cli: use getopt to parse the options Eric Biggers
2018-04-06  2:13 ` Theodore Y. Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.