Re: HelpFormatter help
Greg Ward <[email protected]> Tue, 21 Oct 2003 21:11:34 -0400
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Message-ID | <[email protected]> |
On 20 October 2003, Johan Svedberg said:
> Hi!
>
> First, thanks for making optparse, it's great. I almost have things
> working as I want now, although there are some visual aspects I need a
> hand with. Currently my help message look like this:
>
> usage: lexin.py [OPTIONS]... WORD
>
> options:
> -h, --help show this help message and exit
> -dDICTIONARY, --dictionary=DICTIONARY
> make search in DICTIONARY
> -n, --nocorrection don't try to correct unknown words
> -v, --version output version information and exit
>
> The things I would like to modify in this output is first of all the
> wrapping that's made on the second line, on a 80 width terminal this
> would fit:
Creating your own custom formatter should work here:
formatter = IndentedHelpFormatter(max_help_increment=40, width=80)
parser = OptionParser(..., formatter=formatter)
...play with max_help_increment until you're happy. Untested, of
course. ;-)
> Secondly, I would like it to say "Usage:" instad of "usage:" and
> "Options:" instad of "options:", can this be done?
For "Usage:", you'll need to subclass IndentedHelpFormatter and override
format_usage().
It looks like overriding "options:" means you'd have to
subclassformat_option_help(), which would mean a lot of duplicated code.
Bleccch. Suggestions for refactoring welcome...
Greg
--
Greg Ward <[email protected]> http://www.gerg.ca/
All the world's a stage and most of us are desperately unrehearsed.
-------------------------------------------------------
This SF.net email is sponsored by OSDN developer relations
Here's your chance to show off your extensive product knowledge
We want to know what you know. Tell us and you have a chance to win $100
http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54