Mercurial > public > mercurial-scm > hg
diff mercurial/help.py @ 32566:1b90036f42f0
help: pass commands module by argument
This removes import cycle.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 21 May 2017 16:57:32 +0900 |
parents | 633c635a790a |
children | c9318beb7c1a |
line wrap: on
line diff
--- a/mercurial/help.py Mon May 29 06:06:13 2017 -0700 +++ b/mercurial/help.py Sun May 21 16:57:32 2017 +0900 @@ -114,7 +114,7 @@ return True return False -def topicmatch(ui, kw): +def topicmatch(ui, commands, kw): """Return help topics matching kw. Returns {'section': [(name, summary), ...], ...} where section is @@ -134,7 +134,6 @@ or lowercontains(header) or (callable(doc) and lowercontains(doc(ui)))): results['topics'].append((names[0], header)) - from . import commands # avoid cycle for cmd, entry in commands.table.iteritems(): if len(entry) == 3: summary = entry[2] @@ -299,13 +298,13 @@ addtopicsymbols('hgweb', '.. webcommandsmarker', webcommands.commands, dedent=True) -def help_(ui, name, unknowncmd=False, full=True, subtopic=None, **opts): +def help_(ui, commands, name, unknowncmd=False, full=True, subtopic=None, + **opts): ''' Generate the help for 'name' as unformatted restructured text. If 'name' is None, describe the commands available. ''' - from . import commands # avoid cycle opts = pycompat.byteskwargs(opts) def helpcmd(name, subtopic=None): @@ -569,7 +568,7 @@ rst = [] kw = opts.get('keyword') if kw or name is None and any(opts[o] for o in opts): - matches = topicmatch(ui, name or '') + matches = topicmatch(ui, commands, name or '') helpareas = [] if opts.get('extension'): helpareas += [('extensions', _('Extensions'))] @@ -620,7 +619,8 @@ return ''.join(rst) -def formattedhelp(ui, name, keep=None, unknowncmd=False, full=True, **opts): +def formattedhelp(ui, commands, name, keep=None, unknowncmd=False, full=True, + **opts): """get help for a given topic (as a dotted name) as rendered rst Either returns the rendered help text or raises an exception. @@ -646,7 +646,7 @@ termwidth = ui.termwidth() - 2 if textwidth <= 0 or termwidth < textwidth: textwidth = termwidth - text = help_(ui, name, + text = help_(ui, commands, name, subtopic=subtopic, unknowncmd=unknowncmd, full=full, **opts) formatted, pruned = minirst.format(text, textwidth, keep=keep,