mercurial/commands.py
changeset 3798 17a11f4ff260
parent 3787 8d603f8567ae
child 3799 58133ba5847d
equal deleted inserted replaced
3794:630caaf29815 3798:17a11f4ff260
     8 from demandload import demandload
     8 from demandload import demandload
     9 from node import *
     9 from node import *
    10 from i18n import gettext as _
    10 from i18n import gettext as _
    11 demandload(globals(), "bisect os re sys signal imp urllib pdb shlex stat")
    11 demandload(globals(), "bisect os re sys signal imp urllib pdb shlex stat")
    12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
    12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
    13 demandload(globals(), "difflib patch time")
    13 demandload(globals(), "difflib patch time help")
    14 demandload(globals(), "traceback errno version atexit")
    14 demandload(globals(), "traceback errno version atexit")
    15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
    15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
    16 
    16 
    17 class UnknownCommand(Exception):
    17 class UnknownCommand(Exception):
    18     """Exception raised if command is not in the command table."""
    18     """Exception raised if command is not in the command table."""
  1139                 commands = cmds[f].replace("|",", ")
  1139                 commands = cmds[f].replace("|",", ")
  1140                 ui.write(" %s:\n      %s\n"%(commands, h[f]))
  1140                 ui.write(" %s:\n      %s\n"%(commands, h[f]))
  1141             else:
  1141             else:
  1142                 ui.write(' %-*s   %s\n' % (m, f, h[f]))
  1142                 ui.write(' %-*s   %s\n' % (m, f, h[f]))
  1143 
  1143 
       
  1144     def helptopic(name):
       
  1145         v = None
       
  1146         for i in help.helptable:
       
  1147             l = i.split('|')
       
  1148             if name in l:
       
  1149                 v = i
       
  1150                 header = l[-1]
       
  1151         if not v:
       
  1152             raise UnknownCommand(name)
       
  1153 
       
  1154         # description
       
  1155         doc = help.helptable[v]
       
  1156         if not doc:
       
  1157             doc = _("(No help text available)")
       
  1158 
       
  1159         ui.write("%s\n" % header)
       
  1160         ui.write("%s\n" % doc.rstrip())
       
  1161 
  1144     def helpext(name):
  1162     def helpext(name):
  1145         try:
  1163         try:
  1146             mod = findext(name)
  1164             mod = findext(name)
  1147         except KeyError:
  1165         except KeyError:
  1148             raise UnknownCommand(name)
  1166             raise UnknownCommand(name)
  1161 
  1179 
  1162         modcmds = dict.fromkeys([c.split('|', 1)[0] for c in mod.cmdtable])
  1180         modcmds = dict.fromkeys([c.split('|', 1)[0] for c in mod.cmdtable])
  1163         helplist(modcmds.has_key)
  1181         helplist(modcmds.has_key)
  1164 
  1182 
  1165     if name and name != 'shortlist':
  1183     if name and name != 'shortlist':
  1166         try:
  1184         i = None
  1167             helpcmd(name)
  1185         for f in (helpcmd, helptopic, helpext):
  1168         except UnknownCommand:
  1186             try:
  1169             helpext(name)
  1187                 f(name)
       
  1188                 i = None
       
  1189                 break
       
  1190             except UnknownCommand, inst:
       
  1191                 i = inst
       
  1192         if i:
       
  1193             raise i
  1170 
  1194 
  1171     else:
  1195     else:
  1172         # program name
  1196         # program name
  1173         if ui.verbose or with_version:
  1197         if ui.verbose or with_version:
  1174             version_(ui)
  1198             version_(ui)