comparison mercurial/help.py @ 36250:4174970c9147

help: use cmdutil.parsealiases() to resolve command name This seems slightly better than parsing '^command|name' string by using an ad-hoc pattern.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 08 Jan 2018 12:09:43 +0900
parents c792f7c64f0c
children 1fa35ca345a5
comparison
equal deleted inserted replaced
36249:c792f7c64f0c 36250:4174970c9147
148 docs = _(pycompat.getdoc(entry[0])) or '' 148 docs = _(pycompat.getdoc(entry[0])) or ''
149 if kw in cmd or lowercontains(summary) or lowercontains(docs): 149 if kw in cmd or lowercontains(summary) or lowercontains(docs):
150 doclines = docs.splitlines() 150 doclines = docs.splitlines()
151 if doclines: 151 if doclines:
152 summary = doclines[0] 152 summary = doclines[0]
153 cmdname = cmd.partition('|')[0].lstrip('^') 153 cmdname = cmdutil.parsealiases(cmd)[0]
154 if filtercmd(ui, cmdname, kw, docs): 154 if filtercmd(ui, cmdname, kw, docs):
155 continue 155 continue
156 results['commands'].append((cmdname, summary)) 156 results['commands'].append((cmdname, summary))
157 for name, docs in itertools.chain( 157 for name, docs in itertools.chain(
158 extensions.enabled(False).iteritems(), 158 extensions.enabled(False).iteritems(),
168 except ImportError: 168 except ImportError:
169 # debug message would be printed in extensions.load() 169 # debug message would be printed in extensions.load()
170 continue 170 continue
171 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems(): 171 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
172 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])): 172 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
173 cmdname = cmd.partition('|')[0].lstrip('^') 173 cmdname = cmdutil.parsealiases(cmd)[0]
174 cmddoc = pycompat.getdoc(entry[0]) 174 cmddoc = pycompat.getdoc(entry[0])
175 if cmddoc: 175 if cmddoc:
176 cmddoc = gettext(cmddoc).splitlines()[0] 176 cmddoc = gettext(cmddoc).splitlines()[0]
177 else: 177 else:
178 cmddoc = _('(no help text available)') 178 cmddoc = _('(no help text available)')
326 strict=unknowncmd) 326 strict=unknowncmd)
327 except error.AmbiguousCommand as inst: 327 except error.AmbiguousCommand as inst:
328 # py3k fix: except vars can't be used outside the scope of the 328 # py3k fix: except vars can't be used outside the scope of the
329 # except block, nor can be used inside a lambda. python issue4617 329 # except block, nor can be used inside a lambda. python issue4617
330 prefix = inst.args[0] 330 prefix = inst.args[0]
331 select = lambda c: c.lstrip('^').startswith(prefix) 331 select = lambda c: cmdutil.parsealiases(c)[0].startswith(prefix)
332 rst = helplist(select) 332 rst = helplist(select)
333 return rst 333 return rst
334 334
335 rst = [] 335 rst = []
336 336
417 header = _('list of commands:\n\n') 417 header = _('list of commands:\n\n')
418 418
419 h = {} 419 h = {}
420 cmds = {} 420 cmds = {}
421 for c, e in commands.table.iteritems(): 421 for c, e in commands.table.iteritems():
422 f = c.partition("|")[0] 422 fs = cmdutil.parsealiases(c)
423 if select and not select(f): 423 f = fs[0]
424 p = ''
425 if c.startswith("^"):
426 p = '^'
427 if select and not select(p + f):
424 continue 428 continue
425 if (not select and name != 'shortlist' and 429 if (not select and name != 'shortlist' and
426 e[0].__module__ != commands.__name__): 430 e[0].__module__ != commands.__name__):
427 continue 431 continue
428 if name == "shortlist" and not f.startswith("^"): 432 if name == "shortlist" and not p:
429 continue 433 continue
430 f = f.lstrip("^")
431 doc = pycompat.getdoc(e[0]) 434 doc = pycompat.getdoc(e[0])
432 if filtercmd(ui, f, name, doc): 435 if filtercmd(ui, f, name, doc):
433 continue 436 continue
434 doc = gettext(doc) 437 doc = gettext(doc)
435 if not doc: 438 if not doc:
436 doc = _("(no help text available)") 439 doc = _("(no help text available)")
437 h[f] = doc.splitlines()[0].rstrip() 440 h[f] = doc.splitlines()[0].rstrip()
438 cmds[f] = c.lstrip("^") 441 cmds[f] = '|'.join(fs)
439 442
440 rst = [] 443 rst = []
441 if not h: 444 if not h:
442 if not ui.quiet: 445 if not ui.quiet:
443 rst.append(_('no commands defined\n')) 446 rst.append(_('no commands defined\n'))