Required options in optparse
My humble $0.02:
The phrase "required option" is an oxymoron; the presence of
"required options" in a program is usually a sign of careless user
interface design. optparse doesn't prevent you from implementing
required options, but doesn't give you much help with it either.
I don't know if I necessarily agree with this. While "required option" may
be an oxymoron as far as English is concerned, I think a more accurate
assessment is that "option" is a misnomer, because there is nothing wrong
with requiring one.
Here is an example from a fictional database program. Imagine that to
craete a database I have to specify a name, db size and a some kind of a
device id (the two latter both being integers):
usage: initdb dbname -s size -d dev_id [-t dbtype]
$ initdb mydb -s 1024 -d 1010
Arguably, dbname, size and dev_id could be specified as required
positional _arguments_, but it would be less clear and more error-prone:
usage: initdb dbname size dev_id [-t dbname]
$ initdb mydb 1024 1010
Therefore, I think "required options" should be part of OptionParser.
|All times are GMT. The time now is 08:40 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.