MCPcopy Index your code
hub / github.com/python/cpython / do_help

Method do_help

Lib/cmd.py:302–349  ·  view source on GitHub ↗

List available commands with "help" or detailed help with "help cmd".

(self, arg)

Source from the content-addressed store, hash-verified

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:

Callers 1

test_do_helpMethod · 0.45

Calls 11

get_namesMethod · 0.95
print_topicsMethod · 0.95
cleandocFunction · 0.90
strFunction · 0.85
setFunction · 0.85
funcFunction · 0.50
writeMethod · 0.45
addMethod · 0.45
sortMethod · 0.45
appendMethod · 0.45
removeMethod · 0.45

Tested by 1

test_do_helpMethod · 0.36