mercurial/commands.py
changeset 10364 de1e7099d100
parent 10355 a5576908b589
child 10365 d757bc0c7865
equal deleted inserted replaced
10363:c07974215b3d 10364:de1e7099d100
  1455     displayer = cmdutil.show_changeset(ui, repo, opts)
  1455     displayer = cmdutil.show_changeset(ui, repo, opts)
  1456     for ctx in heads:
  1456     for ctx in heads:
  1457         displayer.show(ctx)
  1457         displayer.show(ctx)
  1458     displayer.close()
  1458     displayer.close()
  1459 
  1459 
  1460 def help_(ui, name=None, with_version=False):
  1460 def help_(ui, name=None, with_version=False, unknowncmd=False):
  1461     """show help for a given topic or a help overview
  1461     """show help for a given topic or a help overview
  1462 
  1462 
  1463     With no arguments, print a list of commands with short help messages.
  1463     With no arguments, print a list of commands with short help messages.
  1464 
  1464 
  1465     Given a topic, extension, or command name, print help for that
  1465     Given a topic, extension, or command name, print help for that
  1488         if with_version:
  1488         if with_version:
  1489             version_(ui)
  1489             version_(ui)
  1490             ui.write('\n')
  1490             ui.write('\n')
  1491 
  1491 
  1492         try:
  1492         try:
  1493             aliases, entry = cmdutil.findcmd(name, table, False)
  1493             aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd)
  1494         except error.AmbiguousCommand, inst:
  1494         except error.AmbiguousCommand, inst:
  1495             # py3k fix: except vars can't be used outside the scope of the
  1495             # py3k fix: except vars can't be used outside the scope of the
  1496             # except block, nor can be used inside a lambda. python issue4617
  1496             # except block, nor can be used inside a lambda. python issue4617
  1497             prefix = inst.args[0]
  1497             prefix = inst.args[0]
  1498             select = lambda c: c.lstrip('^').startswith(prefix)
  1498             select = lambda c: c.lstrip('^').startswith(prefix)
  1499             helplist(_('list of commands:\n\n'), select)
  1499             helplist(_('list of commands:\n\n'), select)
  1500             return
  1500             return
  1501 
  1501 
  1502         # check if it's an invalid alias and display its error if it is
  1502         # check if it's an invalid alias and display its error if it is
  1503         if getattr(entry[0], 'badalias', False):
  1503         if getattr(entry[0], 'badalias', False):
  1504             entry[0](ui)
  1504             if not unknowncmd:
       
  1505                 entry[0](ui)
  1505             return
  1506             return
  1506 
  1507 
  1507         # synopsis
  1508         # synopsis
  1508         if len(entry) > 2:
  1509         if len(entry) > 2:
  1509             if entry[2].startswith('hg'):
  1510             if entry[2].startswith('hg'):
  1590         ui.write("%s\n" % minirst.format(doc, textwidth, indent=4))
  1591         ui.write("%s\n" % minirst.format(doc, textwidth, indent=4))
  1591 
  1592 
  1592     def helpext(name):
  1593     def helpext(name):
  1593         try:
  1594         try:
  1594             mod = extensions.find(name)
  1595             mod = extensions.find(name)
       
  1596             doc = gettext(mod.__doc__) or _('no help text available')
  1595         except KeyError:
  1597         except KeyError:
  1596             raise error.UnknownCommand(name)
  1598             mod = None
  1597 
  1599             doc = extensions.disabledext(name)
  1598         doc = gettext(mod.__doc__) or _('no help text available')
  1600             if not doc:
       
  1601                 raise error.UnknownCommand(name)
       
  1602 
  1599         if '\n' not in doc:
  1603         if '\n' not in doc:
  1600             head, tail = doc, ""
  1604             head, tail = doc, ""
  1601         else:
  1605         else:
  1602             head, tail = doc.split('\n', 1)
  1606             head, tail = doc.split('\n', 1)
  1603         ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head))
  1607         ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head))
  1604         if tail:
  1608         if tail:
  1605             ui.write(minirst.format(tail, textwidth))
  1609             ui.write(minirst.format(tail, textwidth))
  1606             ui.status('\n\n')
  1610             ui.status('\n\n')
  1607 
  1611 
  1608         try:
  1612         if mod:
  1609             ct = mod.cmdtable
  1613             try:
  1610         except AttributeError:
  1614                 ct = mod.cmdtable
  1611             ct = {}
  1615             except AttributeError:
  1612 
  1616                 ct = {}
  1613         modcmds = set([c.split('|', 1)[0] for c in ct])
  1617             modcmds = set([c.split('|', 1)[0] for c in ct])
  1614         helplist(_('list of commands:\n\n'), modcmds.__contains__)
  1618             helplist(_('list of commands:\n\n'), modcmds.__contains__)
       
  1619         else:
       
  1620             ui.write(_('use "hg help extensions" for information on enabling '
       
  1621                        'extensions\n'))
       
  1622 
       
  1623     def helpextcmd(name):
       
  1624         cmd, ext, mod = extensions.disabledcmd(name, ui.config('ui', 'strict'))
       
  1625         doc = gettext(mod.__doc__).splitlines()[0]
       
  1626 
       
  1627         msg = help.listexts(_("'%s' is provided by the following "
       
  1628                               "extension:") % cmd, {ext: doc}, len(ext),
       
  1629                             indent=4)
       
  1630         ui.write(minirst.format(msg, textwidth))
       
  1631         ui.write('\n\n')
       
  1632         ui.write(_('use "hg help extensions" for information on enabling '
       
  1633                    'extensions\n'))
  1615 
  1634 
  1616     if name and name != 'shortlist':
  1635     if name and name != 'shortlist':
  1617         i = None
  1636         i = None
  1618         for f in (helptopic, helpcmd, helpext):
  1637         if unknowncmd:
       
  1638             queries = (helpextcmd,)
       
  1639         else:
       
  1640             queries = (helptopic, helpcmd, helpext, helpextcmd)
       
  1641         for f in queries:
  1619             try:
  1642             try:
  1620                 f(name)
  1643                 f(name)
  1621                 i = None
  1644                 i = None
  1622                 break
  1645                 break
  1623             except error.UnknownCommand, inst:
  1646             except error.UnknownCommand, inst: