Small additions to optparser
Hi Folks, I have two small customizations I've used in most projects I've plugged optparse into. Since they're simple and generic, I'd like to integrate them back in optparser. These features are: - Add a help formatter which uses capitalized headers. - Add a "help" keyword in OptionParser, allowing straightforward addition of a custom help messages. Comments? Also, how are we currently handling changes in optparser? Do we have an "official" maintainer (Greg?). IOW, should I: - Send a proposed patch to SourceForge - Contact the original project - Commit the patch FWIW, here is the proposed functionality: class CapitalizedHelpFormatter(optparse.IndentedHelpFormatter): def format_usage(self, usage): return optparse.IndentedHelpFormatter \ .format_usage(self, usage).capitalize() def format_heading(self, heading): return optparse.IndentedHelpFormatter \ .format_heading(self, heading).capitalize() class OptionParser(optparse.OptionParser): def __init__(self, *args, **kwargs): optparse.OptionParser.__init__(self, *args, **kwargs) self._override_help = kwargs.get("help") def format_help(self, formatter=None): if self._override_help: return self._override_help else: return optparse.OptionParser.format_help(self, formatter) -- Gustavo Niemeyer http://niemeyer.net
On 29 April 2004, Gustavo Niemeyer said:
I have two small customizations I've used in most projects I've plugged optparse into. Since they're simple and generic, I'd like to integrate them back in optparser. These features are:
- Add a help formatter which uses capitalized headers.
Sure, looks simple enough.
- Add a "help" keyword in OptionParser, allowing straightforward addition of a custom help messages.
How is that different from the existing 'description' that David Goodger added for Optik 1.4?
Comments?
Also, how are we currently handling changes in optparser? Do we have an "official" maintainer (Greg?). IOW, should I:
As it says at the top of optparse.py: Originally distributed as Optik; see http://optik.sourceforge.net/ . If you have problems with this module, please do not file bugs, patches, or feature requests with Python; instead, use Optik's SourceForge project page: http://sourceforge.net/projects/optik For support, use the optik-users@lists.sourceforge.net mailing list (http://lists.sourceforge.net/lists/listinfo/optik-users). So either post your patches to optik-users@lists.sourceforge.net, or file 'em on the Optik tracker at SF. Nothing wrong with cc'ing python-dev at the same time, though. Greg -- Greg Ward <gward@python.net> http://www.gerg.ca/ All of science is either physics or stamp collecting.
- Add a help formatter which uses capitalized headers.
Sure, looks simple enough.
Great! Thanks!
How is that different from the existing 'description' that David Goodger added for Optik 1.4?
Here is real example. I have the following help text: HELP = """\ Usage: repsys COMMAND [COMMAND ARGUMENTS] Useful commands: co submit create getspec getsrpm changed authoremail Run "repsys COMMAND --help" for more information. """ Using OptionParser(description=HELP) and "repsys --help", I get: """ Usage: repsys [options] Usage: repsys COMMAND [COMMAND ARGUMENTS] Useful commands: co submit create getspec getsrpm changed authoremail Run "repsys COMMAND --help" for more information. Options: --version show program's version number and exit -h, --help show this help message and exit --debug """ While using OptionParser(help=HELP) and "repsys --help", I get: """ Usage: repsys COMMAND [COMMAND ARGUMENTS] Useful commands: co submit create getspec getsrpm changed authoremail Run "repsys COMMAND --help" for more information. """ [...]
So either post your patches to optik-users@lists.sourceforge.net, or file 'em on the Optik tracker at SF. Nothing wrong with cc'ing python-dev at the same time, though.
Will do that. Thanks! -- Gustavo Niemeyer http://niemeyer.net
participants (2)
-
Greg Ward
-
Gustavo Niemeyer