def do_help(self, arg):
if arg:<EOL><INDENT>try:<EOL><INDENT>func = getattr(self, '<STR_LIT>' + arg)<EOL><DEDENT>except AttributeError:<EOL><INDENT>try:<EOL><INDENT>doc = getattr(self, '<STR_LIT>' + arg).__doc__<EOL>if doc:<EOL><INDENT>self.stdout.write("<STR_LIT>" % str(doc))<EOL>return<EOL><DEDENT><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>self.stdout.write("<STR_LIT>" % str(self.nohelp % (arg,)))<EOL>return<EOL><DEDENT>func()<EOL><DEDENT>else:<EOL><INDENT>names = self.get_names()<EOL>cmds_doc = []<EOL>cmds_undoc = []<EOL>help_page = {}<EOL>for name in names:<EOL><INDENT>if name[:<NUM_LIT:5>] == '<STR_LIT>':<EOL><INDENT>help_page[name[<NUM_LIT:5>:]] = <NUM_LIT:1><EOL><DEDENT><DEDENT>names.sort()<EOL>prevname = '<STR_LIT>'<EOL>for name in names:<EOL><INDENT>if name[:<NUM_LIT:3>] == '<STR_LIT>':<EOL><INDENT>if name == prevname:<EOL><INDENT>continue<EOL><DEDENT>prevname = name<EOL>cmd = name[<NUM_LIT:3>:]<EOL>if cmd in help_page:<EOL><INDENT>cmds_doc.append(cmd)<EOL>del help_page[cmd]<EOL><DEDENT>elif getattr(self, name).__doc__:<EOL><INDENT>cmds_doc.append(cmd)<EOL><DEDENT>else:<EOL><INDENT>cmds_undoc.append(cmd)<EOL><DEDENT><DEDENT><DEDENT>self.stdout.write("<STR_LIT>" % str(self.doc_leader))<EOL>self.print_topics(self.doc_header, cmds_doc, <NUM_LIT:15>, <NUM_LIT>)<EOL>self.print_topics(self.misc_header, list(help_page.keys()), <NUM_LIT:15>, <NUM_LIT>)<EOL>self.print_topics(self.undoc_header, cmds_undoc, <NUM_LIT:15>, <NUM_LIT>)<EOL>for topic in self.command_topics:<EOL><INDENT>topic_cmds = self.command_topics[topic]<EOL>self.print_topics(string.capwords(topic + "<STR_LIT>"), topic_cmds, <NUM_LIT:15>, <NUM_LIT>)<EOL><DEDENT><DEDENT>
List available commands with "help" or detailed help with "help cmd".