##// END OF EJS Templates
help: pass commands module by argument...
Yuya Nishihara -
r32567:1b90036f default
parent child Browse files
Show More
@@ -11,6 +11,7 b' import difflib'
11 import errno
11 import errno
12 import os
12 import os
13 import re
13 import re
14 import sys
14
15
15 from .i18n import _
16 from .i18n import _
16 from .node import (
17 from .node import (
@@ -2745,7 +2746,8 b' def help_(ui, name=None, **opts):'
2745 if ui.verbose:
2746 if ui.verbose:
2746 keep.append('verbose')
2747 keep.append('verbose')
2747
2748
2748 formatted = help.formattedhelp(ui, name, keep=keep, **opts)
2749 commands = sys.modules[__name__]
2750 formatted = help.formattedhelp(ui, commands, name, keep=keep, **opts)
2749 ui.pager('help')
2751 ui.pager('help')
2750 ui.write(formatted)
2752 ui.write(formatted)
2751
2753
@@ -333,7 +333,8 b' def _callcatch(ui, func):'
333 try:
333 try:
334 # check if the command is in a disabled extension
334 # check if the command is in a disabled extension
335 # (but don't check for extensions themselves)
335 # (but don't check for extensions themselves)
336 formatted = help.formattedhelp(ui, inst.args[0], unknowncmd=True)
336 formatted = help.formattedhelp(ui, commands, inst.args[0],
337 unknowncmd=True)
337 ui.warn(nocmdmsg)
338 ui.warn(nocmdmsg)
338 ui.write(formatted)
339 ui.write(formatted)
339 except (error.UnknownCommand, error.Abort):
340 except (error.UnknownCommand, error.Abort):
@@ -114,7 +114,7 b' def filtercmd(ui, cmd, kw, doc):'
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
@@ -134,7 +134,6 b' def topicmatch(ui, kw):'
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]
@@ -299,13 +298,13 b" addtopicsymbols('templates', '.. functio"
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):
@@ -569,7 +568,7 b' def help_(ui, name, unknowncmd=False, fu'
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'))]
@@ -620,7 +619,8 b' def help_(ui, name, unknowncmd=False, fu'
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.
@@ -646,7 +646,7 b' def formattedhelp(ui, name, keep=None, u'
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,
@@ -1374,7 +1374,7 b' def help(web, req, tmpl):'
1374 subtopic = None
1374 subtopic = None
1375
1375
1376 try:
1376 try:
1377 doc = helpmod.help_(u, topic, subtopic=subtopic)
1377 doc = helpmod.help_(u, commands, topic, subtopic=subtopic)
1378 except error.UnknownCommand:
1378 except error.UnknownCommand:
1379 raise ErrorResponse(HTTP_NOT_FOUND)
1379 raise ErrorResponse(HTTP_NOT_FOUND)
1380 return tmpl('help', topic=topicname, doc=doc)
1380 return tmpl('help', topic=topicname, doc=doc)
General Comments 0
You need to be logged in to leave comments. Login now