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 23778
- 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:44:09 -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=eEbsiMhMiU11BeUszxASTGMdPk+olezXCWbd91ukH50=; b=NADgVLqz+RygMyWMMzJ8E+sGZdkQRyE4bu2ZPBL1+7duiWvb+0qnTJsEiZISoJ6O5j QK5Xx5GrHIn/FD3SZVErjmHbv9DbKB5Tvke2PwW7v659Np6rU/jLFYFMUs/AID3RMQr0 biUaRuqID1rQWYDs5TWiId8G4sLmnKCEW7tpNJkrEv41lBQpo2VqZVC+180QlH9ZNi7O 4e00HMvYJLqaVH4uPqDENEmzWgfsKWFXhlrhSftTLfAvy2Ed9yW3OC+mVmKciIyQWWNV +AGIdqu+cLgET1x03j9OvJVxEQjuS0xOSFwCoLnYgZ8TMLOXclk+Ho2gmgYxzOEfnkLJ /g9Q==
- In-reply-to: <632A7107-E065-4C04-B3F1-6362245F1518@dana.is>
- 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> <632A7107-E065-4C04-B3F1-6362245F1518@dana.is>
On 2 Dec 2018, at 18:13, dana <dana@xxxxxxx> wrote:
>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
After i hit send it occurred to me that you can deal with this if you use -E,
but you'll have to do a second pass yourself to catch any bad options that it
leaves behind:
myfunc() {
local i
local -a opts
zparseopts -D -E -a opts a b: c
print -r "options: $opts"
for (( i = 1; i <= $#; i++ )); do
[[ $argv[i] == (-|--) ]] && {
argv[i]=()
break
}
[[ $argv[i] == -* ]] && {
print -ru2 "bad option: $argv[i]"
return 1
}
done
print -r "operands: $*"
}
I *think* that handles everything...?
dana
Messages sorted by:
Reverse Date,
Date,
Thread,
Author