Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

How to handle unknown options in zparseopts



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



Messages sorted by: Reverse Date, Date, Thread, Author