Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to yield an error with zparseopts when non-matching options are seen?
- X-seq: zsh-users 23777
- From: dana <dana@xxxxxxx>
- To: Peng Yu <pengyu.ut@xxxxxxxxx>
- Subject: Re: How to yield an error with zparseopts when non-matching options are seen?
- Date: Sun, 2 Dec 2018 18:13:36 -0600
- Cc: zsh-users <zsh-users@xxxxxxx>
- 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==
- In-reply-to: <CABrM6wkV7yi=5OrwW6JnFSuLMdX0xeryL0VF3fP5YpWGEXHvUA@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CABrM6wkV7yi=5OrwW6JnFSuLMdX0xeryL0VF3fP5YpWGEXHvUA@mail.gmail.com>
On 2 Dec 2018, at 16:28, Peng Yu <pengyu.ut@xxxxxxxxx> 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 == -* ]]`
dana
Messages sorted by:
Reverse Date,
Date,
Thread,
Author