From patchwork Thu Apr 5 21:06:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10325467 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F728600CB for ; Thu, 5 Apr 2018 21:07:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F77A26B41 for ; Thu, 5 Apr 2018 21:07:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03F6A27FA5; Thu, 5 Apr 2018 21:07:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B9F126B41 for ; Thu, 5 Apr 2018 21:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751179AbeDEVHg (ORCPT ); Thu, 5 Apr 2018 17:07:36 -0400 Received: from mail-pl0-f68.google.com ([209.85.160.68]:46362 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750726AbeDEVHf (ORCPT ); Thu, 5 Apr 2018 17:07:35 -0400 Received: by mail-pl0-f68.google.com with SMTP id 59-v6so18312844plc.13 for ; Thu, 05 Apr 2018 14:07:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=5h8ASnnS7yCRQt6zILyzHagrHNGyUez1nJflCZ04iRM=; b=HTTWGvp9uyQdTm1tHRIuJB5lnS7bJwQ5JAMt0M7FUqsIo0i+eM7Nf29LWeMYULAfyf 4g1CzDYJCExsJh51BWY4y3Xs4OHsN4oe7PoXMPH34sCBc8bd8pkGu2l/hzglwSGuxcgK LvOr8naDjBXphKSbfQNlguFHD3WisxzXd22CjjJDHecqwPzCi3jjNeJIZFegC4hFpYu0 Y5A87Rz9dTP/BF0BdpR7rbPJGgT6xYayl1uQbHMPL0ND0JxsxmassvXVPZbzowP+Rf04 MYgJ4hUZSaYRmrRSe9YhnHKnrziqTb0R4VsuopJs3t2noRr65PNd/aa/1G9EAN6jEswa Uk1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5h8ASnnS7yCRQt6zILyzHagrHNGyUez1nJflCZ04iRM=; b=Ys17pCnOpfHNYDJqKt7TsS/WEg8HxBPttNF307KVWy/DlsMlF5mrBb5RiSg6DKZRnw fkfb5bxEU6gOx7Ef+X5LWeYz4wR21om63d4vovY9m5SNKABcN2dsECfOaBfvJyN7CSg+ 62TaV7T2n68EUEKV6T6fznJm+XdknHHPzrykjatBZE1pa5e+3IhUL0v0gvJ6Eit7QQpi 7cJuDqNCi64uQHQMUqu21gOwLyFjXIoe7gYPxIIfh7tYI1vyTd6Zxw8ToIRQ1kv2TLkb LOJX4WkP6yJBdj/NIOuuiPC7TOduMi2bL+62Maj5qrpcOnJmVWdaEc2Hm29cDNfTQlDK 2xAg== X-Gm-Message-State: AElRT7FW0WU5mRkaWIEDfDTaYPEkF3VbFEiHhcZWlgnd4c8qSD47hSbf RMx6Y8lHopYisSfl9MD0wfR5Jw== X-Google-Smtp-Source: AIpwx4/nfMXmbUVstyAOMYLbBBy3lt5uGzSFPGIFROFkKG71xeWXiMjjrkGFZq0NgrgZB7KuOIQuKA== X-Received: by 2002:a17:902:8481:: with SMTP id c1-v6mr23911353plo.304.1522962455001; Thu, 05 Apr 2018 14:07:35 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([2620:15c:17:3:dc28:5c82:b905:e8a8]) by smtp.gmail.com with ESMTPSA id b8sm13462771pgv.17.2018.04.05.14.07.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 14:07:33 -0700 (PDT) From: Eric Biggers To: Theodore Ts'o Cc: fstests@vger.kernel.org, Eric Biggers Subject: [xfstests-bld PATCH] util/parse_cli: use getopt to parse the options Date: Thu, 5 Apr 2018 14:06:44 -0700 Message-Id: <20180405210644.128564-1-ebiggers@google.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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"