util/parse_cli: use getopt to parse the options
PATCH 1/1 util/parse_cli: use getopt to parse the options
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 <[email protected]>
--- kvm-xfstests/util/parse_cli | 69 ++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 5 deletions(-)
kvm-xfstests/util/parse_cli +64 -5
@@ -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"
Signature · 1 line
2.17.0.484.g0c8726318c-goog
Quoted 3 lines · 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'.
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