Re: Re: required options
Greg Ward <[email protected]> Thu, 9 Sep 2004 08:08:01 -0400
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Message-ID | <[email protected]> |
[Robert Collins, in what I hope was a joke, suggested]
> target=TARGET ?
[to which Thorsten Kampe replied]
> That's possible? Looks /good/. Could you give me some hints on how to do
> that?
NoooOOOOOooo!!!!!
The whole reason I wrote Optik in the first place was to prevent a
proliferation of weird, non-standard option syntaxes in the Python
world. There Should Be Only One Way To Do It, and those two ways should
be
foo -f FILENAME
and
foo --file=FILENAME
(Hey, it's not my fault there are two ways---no, THREE ways to do it, if
you count "foo --file FILENAME").
The admonition about required options being oxymoronic in tao.txt is
there because I want people to think twice before asking for that
feature or implementing it themselves, *not* because I think required
options should never exist. Sometimes, a "required option" is the
least-bad solution. It sounds like you may have stumbled across such a
situation.
See examples/required_1.py and required_2.py in the Optik source
distribution for two ways to add required options to an OptionParser.
Of course, you can always do it manually:
if options.filename is None:
parser.error("-f/--filename option is required")
which is what I do on the occasions where I think a required option is
the least-bad alternative. (If you have to write that code more than
once or twice per script, you may have larger problems with your UI.)
Greg
--
Greg Ward <[email protected]> http://www.gerg.ca/
Never try to outstubborn a cat.
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click