From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 1724dbc5 for ; Mon, 3 Dec 2018 00:14:00 +0000 (UTC) Received: (qmail 13996 invoked by alias); 3 Dec 2018 00:13:43 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23777 Received: (qmail 25138 invoked by uid 1010); 3 Dec 2018 00:13:43 -0000 X-Qmail-Scanner-Diagnostics: from mail-it1-f173.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.100.2/25112. spamassassin: 3.4.2. Clear:RC:0(209.85.166.173):SA:0(-1.9/5.0):. Processed in 2.745721 secs); 03 Dec 2018 00:13:43 -0000 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Or1e6u+XK8IoMwjd93EJNuA9i9eVdt5zdb7rMQyNxeA=; b=ISdS9PIrBESaGdDemhycc3k8Gkjnmx4wiBbeIAGpvDYqvlHvStn5B/4e+HFPCxRreS 2OUMpbJevjafLwBzaowEsAsYQyhZoQgGFjvpVcMZ2F3lownxwOCvwYDleQ8yJbfsIRl5 OFH5M+cy/KLdOEHCV48xPSnbWPczOwd2zZt/6R4niZVGiYwEbOWHS1/ysLJTj7wvOvCR xDgo8B22Q6fBidJAbJY65m4IZvo1hr8CfI9SJvZPAeebOA0DlsO0FPwjYYCai9x0QJgg N8tGM7Z4ozDFPONqHoSUSL1i+hJwnmVKmPOg3tr7qJxr0Pjfy40AUrlOuKViVHsjxpJs ad7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=Or1e6u+XK8IoMwjd93EJNuA9i9eVdt5zdb7rMQyNxeA=; b=EKMHPrU6HetMNfXdhlIBfxbjqrfFFqROYzhiFyvEfhBhmkda2ZlnVVQ9w8nkhijTRy d1QtQJZQGF2R4vig5FJd7yrLMFMSQxJ5mx73hnKATz1O+wMZ8DG8yXQVRklmAfnWDj8r 5jH/oXXlsMKihKyaslC6qEacYKcdbv5MkqwnGvrlg06FXYlcgCKmbUVIv0d6oidIxXvB c5e9yJzaUH02COvl1iI3uCaJZVMqqSp5halG5VI8VArR7Q/8VfQ8TuGGaPdl8NfusNEe 1rPNRn/LtrjAPZNcAG8IA8UodXO/d9DXo4m42+TAAigKmlI6+DGlHSeotVWIS3ls6OcH 3pKg== X-Gm-Message-State: AA+aEWacG4CUkoicf4eacW/+fP9tYM+qhMIabjXJu8o9XZXwkP8icRnt lRWUKukxGslk3awXnB8ySozaeQ== X-Google-Smtp-Source: AFSGD/WOQqgy/JCmD7LuugtEaF1tkikqjKXURGXvoDfiJrbpBGYIl1FbfJ41UU9+pb9noJIjxgAbxQ== X-Received: by 2002:a24:53c9:: with SMTP id n192mr6007762itb.8.1543796017770; Sun, 02 Dec 2018 16:13:37 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.0 \(3445.100.39\)) Subject: Re: How to yield an error with zparseopts when non-matching options are seen? From: dana In-Reply-To: Date: Sun, 2 Dec 2018 18:13:36 -0600 Cc: zsh-users Content-Transfer-Encoding: quoted-printable Message-Id: <632A7107-E065-4C04-B3F1-6362245F1518@dana.is> References: To: Peng Yu X-Mailer: Apple Mail (2.3445.100.39) On 2 Dec 2018, at 16:28, Peng Yu wrote: >In the following example, -b has not been defined as an option, but >`zparseopts` return successfully. Is there a way to let it yield an >error when it sees such a case? Not that i know of. If it didn't swallow up `--` you could check to see = if the first element remaining in argv is any other string beginning with a = hyphen, but since it does you can only rely on that method when no other argument to = your function/script can ever start with a hyphen: % myfunc() { local -a opts zparseopts -D -a opts a b c print -r - $? / $opts / $@ } % myfunc -a -b -foo 0 / -a -b / -foo % myfunc -a -b -- -foo 0 / -a -b / -foo If you're certain that that's the case (e.g., the first operand must be = a digit or an absolute path or something), then just abort if `[[ $1 =3D=3D -* = ]]` dana