From: DervishD <zsh@dervishd.net>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: How to handle unknown options in zparseopts
Date: Wed, 31 Aug 2005 17:44:54 +0200 [thread overview]
Message-ID: <20050831154454.GA122@DervishD> (raw)
Hi all :)
After the suggestion of Doug for using zparseopts, I'm facing a
different problem. I don't want my script silently ignore unknown
options, I want to consider that an error. I don't know how to do it
since zparseopts doesn't report errors, so I've written this:
#!/bin/zsh
emulate -L zsh
typeset -A OPTIONS
zparseopts -D -A OPTIONS -- -help+
tmp=$argv[1]
[[ "$tmp[1]" == "-" ]] && {
print "ERROR, unknown option \"$tmp\""
return 1
}
# Handle here the other (valid) options
return 0
That's pretty ugly and not very clean, neither :(
But, worse, zparseopts spits an error in this case:
set -- -a
zparseopts -a array -- a:
OK, it returns '1' but I'm pretty sure that it returns that value
for other errors, so I cannot 'silent' zparseopts by redirecting to
/dev/null and doing my own handling.
Am I missing anything obvious? If I must handle myself unknown
options and the missing argument problem, I think I better use
getopts and handle long options myself :? GNU getopt is just another
pain in the arse, so...
Thanks in advance :)
Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...
next reply other threads:[~2005-08-31 15:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-31 15:44 DervishD [this message]
2005-09-02 16:14 ` Bart Schaefer
2005-09-02 16:35 ` DervishD
2005-09-02 16:54 ` Bart Schaefer
2005-09-02 17:20 ` DervishD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050831154454.GA122@DervishD \
--to=zsh@dervishd.net \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).