Argument parsing

By Filip Salomonsson; published on August 04, 2006.

Argparse is a new module for parsing command-line arguments. The code examples look a bit odd to me, but I should probably check it out anyway. (Note to self.)

Granted, optparse itself isn't purely a bag of love either, but I think what I'd really want is an option/argument parser that does less. These all try to be very fancy, but come on... in most cases, this is what I need:

  • short and long options (-v, --verbose)
  • single-argument options (-o foo.txt, --output=foo.txt)
  • automatic conversion of boolean, string and integer arguments to the corresponding data types
  • non-option arguments as a list (like optparse does it)
  • error messages on type errors, missing required arguments and invalid options
  • (semi-)automatic generation of usage message (--help) doesn't hurt

Any additional features only tend to clutter the API. With getopt and optparse in the standard library, we need less of weird APIS, not more.