comparison mercurial/help.py @ 27378:c709b515218e

help: pass sub-topic into help query functions While we will likely only use this variable in helptopic(), all these functions are called with the same arguments, so we have to be consistent.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 13 Dec 2015 11:29:01 -0800
parents d1c998d7b103
children 2278870bb997
comparison
equal deleted inserted replaced
27377:d1c998d7b103 27378:c709b515218e
261 'name' is None, describe the commands available. 261 'name' is None, describe the commands available.
262 ''' 262 '''
263 263
264 import commands # avoid cycle 264 import commands # avoid cycle
265 265
266 def helpcmd(name): 266 def helpcmd(name, subtopic=None):
267 try: 267 try:
268 aliases, entry = cmdutil.findcmd(name, commands.table, 268 aliases, entry = cmdutil.findcmd(name, commands.table,
269 strict=unknowncmd) 269 strict=unknowncmd)
270 except error.AmbiguousCommand as inst: 270 except error.AmbiguousCommand as inst:
271 # py3k fix: except vars can't be used outside the scope of the 271 # py3k fix: except vars can't be used outside the scope of the
430 rst.append(_('\n(use "hg help -v%s" to show built-in aliases ' 430 rst.append(_('\n(use "hg help -v%s" to show built-in aliases '
431 'and global options)\n') 431 'and global options)\n')
432 % (name and " " + name or "")) 432 % (name and " " + name or ""))
433 return rst 433 return rst
434 434
435 def helptopic(name): 435 def helptopic(name, subtopic=None):
436 for names, header, doc in helptable: 436 for names, header, doc in helptable:
437 if name in names: 437 if name in names:
438 break 438 break
439 else: 439 else:
440 raise error.UnknownCommand(name) 440 raise error.UnknownCommand(name)
458 'the %s command\n') % (name, name)) 458 'the %s command\n') % (name, name))
459 except error.UnknownCommand: 459 except error.UnknownCommand:
460 pass 460 pass
461 return rst 461 return rst
462 462
463 def helpext(name): 463 def helpext(name, subtopic=None):
464 try: 464 try:
465 mod = extensions.find(name) 465 mod = extensions.find(name)
466 doc = gettext(mod.__doc__) or _('no help text available') 466 doc = gettext(mod.__doc__) or _('no help text available')
467 except KeyError: 467 except KeyError:
468 mod = None 468 mod = None
494 else: 494 else:
495 rst.append(_('(use "hg help extensions" for information on enabling' 495 rst.append(_('(use "hg help extensions" for information on enabling'
496 ' extensions)\n')) 496 ' extensions)\n'))
497 return rst 497 return rst
498 498
499 def helpextcmd(name): 499 def helpextcmd(name, subtopic=None):
500 cmd, ext, mod = extensions.disabledcmd(ui, name, 500 cmd, ext, mod = extensions.disabledcmd(ui, name,
501 ui.configbool('ui', 'strict')) 501 ui.configbool('ui', 'strict'))
502 doc = gettext(mod.__doc__).splitlines()[0] 502 doc = gettext(mod.__doc__).splitlines()[0]
503 503
504 rst = listexts(_("'%s' is provided by the following " 504 rst = listexts(_("'%s' is provided by the following "
543 queries += [helpcmd] 543 queries += [helpcmd]
544 if not queries: 544 if not queries:
545 queries = (helptopic, helpcmd, helpext, helpextcmd) 545 queries = (helptopic, helpcmd, helpext, helpextcmd)
546 for f in queries: 546 for f in queries:
547 try: 547 try:
548 rst = f(name) 548 rst = f(name, subtopic)
549 break 549 break
550 except error.UnknownCommand: 550 except error.UnknownCommand:
551 pass 551 pass
552 else: 552 else:
553 if unknowncmd: 553 if unknowncmd: