# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1236859112 14400 # Node ID 5da7d72e72ee0d8a893a581488b7f871519db5dd # Parent 3f8fac776845d1bb72038ce326e3877006c2d97c print full help on -h diff -r 3f8fac776845 -r 5da7d72e72ee cmd2.py --- 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) diff -r 3f8fac776845 -r 5da7d72e72ee setup.py --- a/setup.py Tue Mar 10 16:42:06 2009 -0400 +++ b/setup.py Thu Mar 12 07:58:32 2009 -0400 @@ -3,7 +3,7 @@ setup( name="cmd2", - version="0.4.7", + version="0.4.8", py_modules=["cmd2",], # metadata for upload to PyPI