Mercurial > python-cmd2
changeset 211:5da7d72e72ee
print full help on -h
author | catherine@Elli.myhome.westell.com |
---|---|
date | Thu, 12 Mar 2009 07:58:32 -0400 |
parents | 3f8fac776845 |
children | 9c4c4d012a92 |
files | cmd2.py setup.py |
diffstat | 2 files changed, 13 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd2.py Tue Mar 10 16:42:06 2009 -0400 +++ b/cmd2.py Thu Mar 12 07:58:32 2009 -0400 @@ -27,13 +27,21 @@ import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest import unittest, string, datetime from optparse import make_option -__version__ = '0.4.7' +__version__ = '0.4.8' class OptionParser(optparse.OptionParser): def exit(self, status=0, msg=None): self.values._exit = True if msg: print msg + + def print_help(self, *args, **kwargs): + # now, I need to call help of the calling function. Hmm. + try: + print self._func.__doc__ + except AttributeError: + pass + optparse.OptionParser.print_help(self, *args, **kwargs) def error(self, msg): """error(msg : string) @@ -59,6 +67,7 @@ for opt in option_list: optionParser.add_option(opt) optionParser.set_usage("%s [options] arg" % func.__name__.strip('do_')) + optionParser._func = func def newFunc(instance, arg): try: opts, newArgList = optionParser.parse_args(arg.split()) # doesn't understand quoted strings shouldn't be dissected! @@ -246,13 +255,14 @@ }) def do_help(self, arg): - cmd.Cmd.do_help(self, arg) try: fn = getattr(self, 'do_' + arg) if fn and fn.optionParser: fn.optionParser.print_help(file=self.stdout) + return except AttributeError: pass + cmd.Cmd.do_help(self, arg) def __init__(self, *args, **kwargs): cmd.Cmd.__init__(self, *args, **kwargs)