=== modified file 'Doc/library/cmd.rst' --- Doc/library/cmd.rst 2009-04-05 21:20:44 +0000 +++ Doc/library/cmd.rst 2010-02-11 18:12:41 +0000 @@ -80,7 +80,13 @@ method, called with an argument ``'bar'``, invokes the corresponding method :meth:`help_bar`. With no argument, :meth:`do_help` lists all available help topics (that is, all commands with corresponding :meth:`help_\*` methods), and - also lists any undocumented commands. + also lists any undocumented commands. If a `do` method has a doc string, + the method is also considered documented, and the doc string is displayed as + the help text for the command. A number of characters equal to the number + of whitespace characters on the first non-blank line of the doc string is + stripped from the front of all subsequent doc string lines. This allows the + doc string to be indented naturally but to display without the extra + indentation. .. method:: Cmd.onecmd(str) === modified file 'Lib/cmd.py' --- Lib/cmd.py 2010-01-09 18:53:06 +0000 +++ Lib/cmd.py 2010-02-11 18:17:10 +0000 @@ -297,7 +297,16 @@ try: doc=getattr(self, 'do_' + arg).__doc__ if doc: - self.stdout.write("%s\n"%str(doc)) + lines = iter(doc.splitlines()) + for line in lines: + if line.strip(): + padlen = len(line) - len(line.lstrip()) + self.stdout.write(line[padlen:]+'\n') + break + else: + self.stdout.write(line+'\n') + for line in lines: + self.stdout.write(line[padlen:]+'\n') return except AttributeError: pass === modified file 'Lib/test/test_cmd.py' --- Lib/test/test_cmd.py 2010-01-09 18:53:06 +0000 +++ Lib/test/test_cmd.py 2010-02-11 18:39:45 +0000 @@ -77,17 +77,21 @@ *** No help on testet >>> mycmd.do_help("add") help text for add + >>> mycmd.onecmd("help exit") + + exit the loop + >>> mycmd.onecmd("help add") help text for add >>> mycmd.do_help("") Documented commands (type help ): ======================================== - add + add exit Undocumented commands: ====================== - exit help shell + help shell Test for the function print_topics(): @@ -114,6 +118,8 @@ and let it execute This test includes the preloop(), postloop(), default(), emptyline(), parseline(), do_help() functions + Note that the expected output depends on which command was executed + last in the tests before this one: 'help add' is the expectation. >>> mycmd.use_rawinput=0 >>> mycmd.cmdqueue=["", "add", "add 4 5", "help", "help add","exit"] >>> mycmd.cmdloop() @@ -124,11 +130,11 @@ Documented commands (type help ): ======================================== - add + add exit Undocumented commands: ====================== - exit help shell + help shell help text for add Hello from postloop @@ -166,6 +172,9 @@ return def do_exit(self, arg): + """ + exit the loop + """ return True def test_main(verbose=None):