List available commands with "help" or detailed help with "help cmd".
(self, arg)
| 300 | return list(commands | topics) |
| 301 | |
| 302 | def do_help(self, arg): |
| 303 | 'List available commands with "help" or detailed help with "help cmd".' |
| 304 | if arg: |
| 305 | # XXX check arg syntax |
| 306 | try: |
| 307 | func = getattr(self, 'help_' + arg) |
| 308 | except AttributeError: |
| 309 | from inspect import cleandoc |
| 310 | |
| 311 | try: |
| 312 | doc=getattr(self, 'do_' + arg).__doc__ |
| 313 | doc = cleandoc(doc) |
| 314 | if doc: |
| 315 | self.stdout.write("%s\n"%str(doc)) |
| 316 | return |
| 317 | except AttributeError: |
| 318 | pass |
| 319 | self.stdout.write("%s\n"%str(self.nohelp % (arg,))) |
| 320 | return |
| 321 | func() |
| 322 | else: |
| 323 | names = self.get_names() |
| 324 | cmds_doc = [] |
| 325 | cmds_undoc = [] |
| 326 | topics = set() |
| 327 | for name in names: |
| 328 | if name[:5] == 'help_': |
| 329 | topics.add(name[5:]) |
| 330 | names.sort() |
| 331 | # There can be duplicates if routines overridden |
| 332 | prevname = '' |
| 333 | for name in names: |
| 334 | if name[:3] == 'do_': |
| 335 | if name == prevname: |
| 336 | continue |
| 337 | prevname = name |
| 338 | cmd=name[3:] |
| 339 | if cmd in topics: |
| 340 | cmds_doc.append(cmd) |
| 341 | topics.remove(cmd) |
| 342 | elif getattr(self, name).__doc__: |
| 343 | cmds_doc.append(cmd) |
| 344 | else: |
| 345 | cmds_undoc.append(cmd) |
| 346 | self.stdout.write("%s\n"%str(self.doc_leader)) |
| 347 | self.print_topics(self.doc_header, cmds_doc, 15,80) |
| 348 | self.print_topics(self.misc_header, sorted(topics),15,80) |
| 349 | self.print_topics(self.undoc_header, cmds_undoc, 15,80) |
| 350 | |
| 351 | def print_topics(self, header, cmds, cmdlen, maxcol): |
| 352 | if cmds: |