mercurial/dispatch.py
changeset 40414 444861dc1e55
parent 40402 106adc261492
child 40587 5542bc9125c9
equal deleted inserted replaced
40413:1ddd202c47d9 40414:444861dc1e55
    35     help,
    35     help,
    36     hg,
    36     hg,
    37     hook,
    37     hook,
    38     profiling,
    38     profiling,
    39     pycompat,
    39     pycompat,
       
    40     registrar,
    40     scmutil,
    41     scmutil,
    41     ui as uimod,
    42     ui as uimod,
    42     util,
    43     util,
    43 )
    44 )
    44 
    45 
   501                 cmd = re.sub(br'\$(\d+|\$)', _checkvar, shdef)
   502                 cmd = re.sub(br'\$(\d+|\$)', _checkvar, shdef)
   502                 cmd = aliasinterpolate(self.name, args, cmd)
   503                 cmd = aliasinterpolate(self.name, args, cmd)
   503                 return ui.system(cmd, environ=env,
   504                 return ui.system(cmd, environ=env,
   504                                  blockedtag='alias_%s' % self.name)
   505                                  blockedtag='alias_%s' % self.name)
   505             self.fn = fn
   506             self.fn = fn
       
   507             self.alias = True
   506             self._populatehelp(ui, name, shdef, self.fn)
   508             self._populatehelp(ui, name, shdef, self.fn)
   507             return
   509             return
   508 
   510 
   509         try:
   511         try:
   510             args = pycompat.shlexsplit(self.definition)
   512             args = pycompat.shlexsplit(self.definition)
   528                 self.fn, self.opts, cmdhelp = tableentry
   530                 self.fn, self.opts, cmdhelp = tableentry
   529             else:
   531             else:
   530                 self.fn, self.opts = tableentry
   532                 self.fn, self.opts = tableentry
   531                 cmdhelp = None
   533                 cmdhelp = None
   532 
   534 
       
   535             self.alias = True
   533             self._populatehelp(ui, name, cmd, self.fn, cmdhelp)
   536             self._populatehelp(ui, name, cmd, self.fn, cmdhelp)
   534 
   537 
   535         except error.UnknownCommand:
   538         except error.UnknownCommand:
   536             self.badalias = (_("alias '%s' resolves to unknown command '%s'")
   539             self.badalias = (_("alias '%s' resolves to unknown command '%s'")
   537                              % (self.name, cmd))
   540                              % (self.name, cmd))
   541                              % (self.name, cmd))
   544                              % (self.name, cmd))
   542 
   545 
   543     def _populatehelp(self, ui, name, cmd, fn, defaulthelp=None):
   546     def _populatehelp(self, ui, name, cmd, fn, defaulthelp=None):
   544         # confine strings to be passed to i18n.gettext()
   547         # confine strings to be passed to i18n.gettext()
   545         cfg = {}
   548         cfg = {}
   546         for k in ('doc', 'help'):
   549         for k in ('doc', 'help', 'category'):
   547             v = ui.config('alias', '%s:%s' % (name, k), None)
   550             v = ui.config('alias', '%s:%s' % (name, k), None)
   548             if v is None:
   551             if v is None:
   549                 continue
   552                 continue
   550             if not encoding.isasciistr(v):
   553             if not encoding.isasciistr(v):
   551                 self.badalias = (_("non-ASCII character in alias definition "
   554                 self.badalias = (_("non-ASCII character in alias definition "
   556         self.help = cfg.get('help', defaulthelp or '')
   559         self.help = cfg.get('help', defaulthelp or '')
   557         if self.help and self.help.startswith("hg " + cmd):
   560         if self.help and self.help.startswith("hg " + cmd):
   558             # drop prefix in old-style help lines so hg shows the alias
   561             # drop prefix in old-style help lines so hg shows the alias
   559             self.help = self.help[4 + len(cmd):]
   562             self.help = self.help[4 + len(cmd):]
   560 
   563 
       
   564         self.owndoc = 'doc' in cfg
   561         doc = cfg.get('doc', pycompat.getdoc(fn))
   565         doc = cfg.get('doc', pycompat.getdoc(fn))
   562         if doc is not None:
   566         if doc is not None:
   563             doc = pycompat.sysstr(doc)
   567             doc = pycompat.sysstr(doc)
   564         self.__doc__ = doc
   568         self.__doc__ = doc
       
   569 
       
   570         self.helpcategory = cfg.get('category', registrar.command.CATEGORY_NONE)
   565 
   571 
   566     @property
   572     @property
   567     def args(self):
   573     def args(self):
   568         args = pycompat.maplist(util.expandpath, self.givenargs)
   574         args = pycompat.maplist(util.expandpath, self.givenargs)
   569         return aliasargs(self.fn, args)
   575         return aliasargs(self.fn, args)
   611         self.ui = ui
   617         self.ui = ui
   612         self.name = name
   618         self.name = name
   613         self.definition = definition
   619         self.definition = definition
   614         self.cmdtable = cmdtable.copy()
   620         self.cmdtable = cmdtable.copy()
   615         self.source = source
   621         self.source = source
       
   622         self.alias = True
   616 
   623 
   617     @util.propertycache
   624     @util.propertycache
   618     def _aliasdef(self):
   625     def _aliasdef(self):
   619         return cmdalias(self.ui, self.name, self.definition, self.cmdtable,
   626         return cmdalias(self.ui, self.name, self.definition, self.cmdtable,
   620                         self.source)
   627                         self.source)