Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
32565:5313d98089f5 | 32566:1b90036f42f0 |
---|---|
112 return True | 112 return True |
113 if not ui.verbose and doc and any(w in doc for w in _exclkeywords): | 113 if not ui.verbose and doc and any(w in doc for w in _exclkeywords): |
114 return True | 114 return True |
115 return False | 115 return False |
116 | 116 |
117 def topicmatch(ui, kw): | 117 def topicmatch(ui, commands, kw): |
118 """Return help topics matching kw. | 118 """Return help topics matching kw. |
119 | 119 |
120 Returns {'section': [(name, summary), ...], ...} where section is | 120 Returns {'section': [(name, summary), ...], ...} where section is |
121 one of topics, commands, extensions, or extensioncommands. | 121 one of topics, commands, extensions, or extensioncommands. |
122 """ | 122 """ |
132 # Old extensions may use a str as doc. | 132 # Old extensions may use a str as doc. |
133 if (sum(map(lowercontains, names)) | 133 if (sum(map(lowercontains, names)) |
134 or lowercontains(header) | 134 or lowercontains(header) |
135 or (callable(doc) and lowercontains(doc(ui)))): | 135 or (callable(doc) and lowercontains(doc(ui)))): |
136 results['topics'].append((names[0], header)) | 136 results['topics'].append((names[0], header)) |
137 from . import commands # avoid cycle | |
138 for cmd, entry in commands.table.iteritems(): | 137 for cmd, entry in commands.table.iteritems(): |
139 if len(entry) == 3: | 138 if len(entry) == 3: |
140 summary = entry[2] | 139 summary = entry[2] |
141 else: | 140 else: |
142 summary = '' | 141 summary = '' |
297 addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters) | 296 addtopicsymbols('templates', '.. filtersmarker', templatefilters.filters) |
298 addtopicsymbols('templates', '.. functionsmarker', templater.funcs) | 297 addtopicsymbols('templates', '.. functionsmarker', templater.funcs) |
299 addtopicsymbols('hgweb', '.. webcommandsmarker', webcommands.commands, | 298 addtopicsymbols('hgweb', '.. webcommandsmarker', webcommands.commands, |
300 dedent=True) | 299 dedent=True) |
301 | 300 |
302 def help_(ui, name, unknowncmd=False, full=True, subtopic=None, **opts): | 301 def help_(ui, commands, name, unknowncmd=False, full=True, subtopic=None, |
302 **opts): | |
303 ''' | 303 ''' |
304 Generate the help for 'name' as unformatted restructured text. If | 304 Generate the help for 'name' as unformatted restructured text. If |
305 'name' is None, describe the commands available. | 305 'name' is None, describe the commands available. |
306 ''' | 306 ''' |
307 | 307 |
308 from . import commands # avoid cycle | |
309 opts = pycompat.byteskwargs(opts) | 308 opts = pycompat.byteskwargs(opts) |
310 | 309 |
311 def helpcmd(name, subtopic=None): | 310 def helpcmd(name, subtopic=None): |
312 try: | 311 try: |
313 aliases, entry = cmdutil.findcmd(name, commands.table, | 312 aliases, entry = cmdutil.findcmd(name, commands.table, |
567 | 566 |
568 | 567 |
569 rst = [] | 568 rst = [] |
570 kw = opts.get('keyword') | 569 kw = opts.get('keyword') |
571 if kw or name is None and any(opts[o] for o in opts): | 570 if kw or name is None and any(opts[o] for o in opts): |
572 matches = topicmatch(ui, name or '') | 571 matches = topicmatch(ui, commands, name or '') |
573 helpareas = [] | 572 helpareas = [] |
574 if opts.get('extension'): | 573 if opts.get('extension'): |
575 helpareas += [('extensions', _('Extensions'))] | 574 helpareas += [('extensions', _('Extensions'))] |
576 if opts.get('command'): | 575 if opts.get('command'): |
577 helpareas += [('commands', _('Commands'))] | 576 helpareas += [('commands', _('Commands'))] |
618 rst = [_("Mercurial Distributed SCM\n"), '\n'] | 617 rst = [_("Mercurial Distributed SCM\n"), '\n'] |
619 rst.extend(helplist(None, **pycompat.strkwargs(opts))) | 618 rst.extend(helplist(None, **pycompat.strkwargs(opts))) |
620 | 619 |
621 return ''.join(rst) | 620 return ''.join(rst) |
622 | 621 |
623 def formattedhelp(ui, name, keep=None, unknowncmd=False, full=True, **opts): | 622 def formattedhelp(ui, commands, name, keep=None, unknowncmd=False, full=True, |
623 **opts): | |
624 """get help for a given topic (as a dotted name) as rendered rst | 624 """get help for a given topic (as a dotted name) as rendered rst |
625 | 625 |
626 Either returns the rendered help text or raises an exception. | 626 Either returns the rendered help text or raises an exception. |
627 """ | 627 """ |
628 if keep is None: | 628 if keep is None: |
644 section = remaining | 644 section = remaining |
645 textwidth = ui.configint('ui', 'textwidth', 78) | 645 textwidth = ui.configint('ui', 'textwidth', 78) |
646 termwidth = ui.termwidth() - 2 | 646 termwidth = ui.termwidth() - 2 |
647 if textwidth <= 0 or termwidth < textwidth: | 647 if textwidth <= 0 or termwidth < textwidth: |
648 textwidth = termwidth | 648 textwidth = termwidth |
649 text = help_(ui, name, | 649 text = help_(ui, commands, name, |
650 subtopic=subtopic, unknowncmd=unknowncmd, full=full, **opts) | 650 subtopic=subtopic, unknowncmd=unknowncmd, full=full, **opts) |
651 | 651 |
652 formatted, pruned = minirst.format(text, textwidth, keep=keep, | 652 formatted, pruned = minirst.format(text, textwidth, keep=keep, |
653 section=section) | 653 section=section) |
654 | 654 |