zsh-users
 help / color / mirror / code / Atom feed
* How to handle unknown options in zparseopts
@ 2005-08-31 15:44 DervishD
  2005-09-02 16:14 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: DervishD @ 2005-08-31 15:44 UTC (permalink / raw)
  To: Zsh Users

    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...


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-09-02 17:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-31 15:44 How to handle unknown options in zparseopts DervishD
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

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).