This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: optparse error method doesn't print option info
Type: enhancement Stage:
Components: Library (Lib) Versions:
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: gward Nosy List: gward, mhammond, nestler
Priority: normal Keywords:

Created on 2004-07-30 01:05 by nestler, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg54200 - (view) Author: Ivan Nestlerode (nestler) Date: 2004-07-30 01:05
When there is an error in optparse.OptionParser's
parse_args() method, (like if the user types an
argument to an option that doesn't take one), a terse
one-line error message is printed and the program exits.

I think it would be significantly more useful if the
option documentation were printed out too, but I have
no way to make this happen currently (since exit is

Please expose a toggle to print out the option info
(that stuff that is printed with -h) when there is a
parsing error. It could probably be implemented as a
Boolean argument to the OptionParser constructor.

To illustrate what I'm talking about, consider a
program called mktoc that uses the optparse module for
its parsing. Here are two runs of it.

# This prints out the one-liner usage string and the
options details
$ mktoc -h
usage: mktoc [options] [showdirectoryname]

  --version             show program's version number
and exit
  -h, --help            show this help message and exit
  -a, --auto            run automatically
  -bBAND, --band=BAND   specify the band manually
  -c, --cdrdao          output cdrdao TOC format (the
  -d, --data            make a data disc instead of an
audio disc
  -k, --k3b             output K3B project format

# This only prints out the one-liner usage string which
is basically
# useless without the option details. This is what
comes out of the
# error() method of the parser object.
$ mktoc --cdrdao=foo
usage: mktoc [options] [showdirectoryname]

mktoc: error: --cdrdao option does not take a value

If it isn't clear, the reason I think the option info
should be printed is for usability (if the user is
confused enough to put arguments where they don't
belong or some such thing, they probably need the more
verbose message).


msg54201 - (view) Author: Mark Hammond (mhammond) * (Python committer) Date: 2004-08-01 00:10
Logged In: YES 

It is not clear to me that the usability is better with your
patch - experienced users who simply made a typo, or had a
brain-fart will often *not* want the full usage.
You could catch the SystemExit exception, and print your
usage there.  You may also be able to override your "usage"
string so it includes "use --help for more details"
msg54202 - (view) Author: Greg Ward (gward) (Python committer) Date: 2004-11-06 02:20
Logged In: YES 

Please prepare a patch (relative to Optik 1.5a2) to explain
what you mean.  Otherwise I will probably reject this
feature request.  (It doesn't seem very useful to me.)
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40659
2004-07-30 01:05:06nestlercreate