Ideas for a module to process command line arguments
Alice Bevan–McGregor
alice at gothcandy.com
Wed Jan 12 12:09:56 EST 2011
On 2011-01-11 21:41:24 -0800, Michele Simionato said:
> Originally plac too was able to recognize flags automatically by
> looking at the default value (if the default value is a boolean then
> the option is a flag); however I removed that functionality because I
> wanted to be able to differentiate between flag and (smart) options
> (see
> http://micheles.googlecode.com/hg/plac/doc/plac.html#scripts-with-options-and-smart-options).
Not
>
entirely sure what you mean by 'smart' options. If your'e referring to
using a single hyphen and a list of characters to represent a long
option (which, to the rest of the world, use two leading hyphens) then
that's pretty weird. ;)
Consider most of the GNU tools:
ls -lvh
tar -xzvf file.tgz (goes so far as to make the leading hyphen optional!)
less -ceF logfile
bc -qw
ps -aux (same as tar)
And even third-party tools:
mysql -fH
pg_dump -abO ...
One major system in the world that doesn't really differentiate between
long and short options is... DOS, and by extension, Windows. But they
also use / as a switch character.
Anyway; I'm happy with what I have wrought (and am continuing to update
with support for class-based sub-command dispatch) and will be
utilizing it for all scripts in the Marrow suite. To each their own,
but reinvention itself can be for motivations other than NIH. I wanted
something pure-Python, portable across the 3k barrier without code
modification (no 2to3), that didn't use optparse, getopt, or argparse
and basically be a translation layer. It can be simpler than that, as
marrow.script demonstrates.
- Alice.
More information about the Python-list
mailing list