I always invoke optparse like this:
---
# specify constants
PROG_VERSION = "Version 0.1, January NN, 2004"
PROG_DESCRIPTION = """tool.py counts lines in each file.\n
Author: Tomi Mickelsson. """ + PROG_VERSION
# parse options and arguments
parser = OptionParser(PROG_USAGE,
option_list = option_list,
version = PROG_VERSION,
description = PROG_DESCRIPTION)
---
That is, I always specify the description info.
However, I'm not happy with the way description gets
formatted:
---
usage: tool.py [-v] arg1 arg2
tool.py counts lines in each file. Author: Tomi
Mickelsson. Version 0.1, January NN, 2004
options:
-v verbose
-h, --help show this help message and exit
---
My new lines are removed from the description field and
the result looks awful and arbitrary. I want to control
the new lines.
Could there be an option to insert "hard" new lines in
the description field? I wouldn't want to override
OptionParser.format_description function, I want an
easy solution that doesn't pollute my scripts; I use
optparse in all my scripts, it's a very useful module.
It seems that 1.5a2 works the same as earlier versions.
Logged In: YES
user_id=350137
I would like to additionally request that newlines be
honored in all areas, and support for them be placed in all
areas.
I'm going to submit an RFE for an "example" arg to
OptionParser, which would also need newline support.
I also recommend that newlines only get inserted where
requested. So by default without any explicit user-inserted
newlines, the output is:
$ tool.py --help
usage: tool.py [...] <<usage>>
Counts lines... <<description>>
options: <<option_list>>
-h, --help ...
example: <<example>>
tool.py -z foo
Report bugs to <foo@bar.com> <<epilog>>
* * *
With this in place, users have much more flexibility in how
to lay out their help. This is especially useful when using
a tool like "help2man" which expects newlines in certain
places in order to create a proper manpage.
Thanks Greg!
Logged In: YES
user_id=297861
I ran into this same issue with one of my own scripts. I
took a look at the source and it's easy to fix -- textwrap
(which handles all the Optik wrapping) has a
replace_whitespace argument which defaults to true. I
hacked up a new HelpFormatter which supports that option.
I've also ported the changes to Optik 1.5 and will submitted
the patch to the project. It adds
"preserve_whitespace=True/False" to the HelpFormatter init
(defaults to False for backwards compatibility) and also
adds a SUPPRESS_METAVAR special value which does what it says.
Logged In: NO
I've solved this in this thread on comp.lang.python in case you need some working code.
http://groups.google.com/group/comp.lang.python/browse_frm/thread/6df6e6b541a15bc2/09f28e26af0699b1