Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/help.py @ 26413:e0c572d4d112
help: pass around ui to doc loader (API)
This is necessary to hide DEPRECATED items conditionally.
Flagged as API change because it will break "hg help git|subversion".
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 26 Sep 2015 12:06:30 +0900 |
parents | 51b309ce6c7d |
children | c44b507e7c78 |
comparison
equal
deleted
inserted
replaced
26412:7e8e3c0920a6 | 26413:e0c572d4d112 |
---|---|
32 if not showdeprecated and any(w in desc for w in _exclkeywords): | 32 if not showdeprecated and any(w in desc for w in _exclkeywords): |
33 continue | 33 continue |
34 rst.append('%s:%s: %s\n' % (' ' * indent, name, desc)) | 34 rst.append('%s:%s: %s\n' % (' ' * indent, name, desc)) |
35 return rst | 35 return rst |
36 | 36 |
37 def extshelp(): | 37 def extshelp(ui): |
38 rst = loaddoc('extensions')().splitlines(True) | 38 rst = loaddoc('extensions')(ui).splitlines(True) |
39 rst.extend(listexts( | 39 rst.extend(listexts( |
40 _('enabled extensions:'), extensions.enabled(), showdeprecated=True)) | 40 _('enabled extensions:'), extensions.enabled(), showdeprecated=True)) |
41 rst.extend(listexts(_('disabled extensions:'), extensions.disabled())) | 41 rst.extend(listexts(_('disabled extensions:'), extensions.disabled())) |
42 doc = ''.join(rst) | 42 doc = ''.join(rst) |
43 return doc | 43 return doc |
81 def indicateomitted(rst, omitted, notomitted=None): | 81 def indicateomitted(rst, omitted, notomitted=None): |
82 rst.append('\n\n.. container:: omitted\n\n %s\n\n' % omitted) | 82 rst.append('\n\n.. container:: omitted\n\n %s\n\n' % omitted) |
83 if notomitted: | 83 if notomitted: |
84 rst.append('\n\n.. container:: notomitted\n\n %s\n\n' % notomitted) | 84 rst.append('\n\n.. container:: notomitted\n\n %s\n\n' % notomitted) |
85 | 85 |
86 def topicmatch(kw): | 86 def topicmatch(ui, kw): |
87 """Return help topics matching kw. | 87 """Return help topics matching kw. |
88 | 88 |
89 Returns {'section': [(name, summary), ...], ...} where section is | 89 Returns {'section': [(name, summary), ...], ...} where section is |
90 one of topics, commands, extensions, or extensioncommands. | 90 one of topics, commands, extensions, or extensioncommands. |
91 """ | 91 """ |
99 } | 99 } |
100 for names, header, doc in helptable: | 100 for names, header, doc in helptable: |
101 # Old extensions may use a str as doc. | 101 # Old extensions may use a str as doc. |
102 if (sum(map(lowercontains, names)) | 102 if (sum(map(lowercontains, names)) |
103 or lowercontains(header) | 103 or lowercontains(header) |
104 or (callable(doc) and lowercontains(doc()))): | 104 or (callable(doc) and lowercontains(doc(ui)))): |
105 results['topics'].append((names[0], header)) | 105 results['topics'].append((names[0], header)) |
106 import commands # avoid cycle | 106 import commands # avoid cycle |
107 for cmd, entry in commands.table.iteritems(): | 107 for cmd, entry in commands.table.iteritems(): |
108 if len(entry) == 3: | 108 if len(entry) == 3: |
109 summary = entry[2] | 109 summary = entry[2] |
137 return results | 137 return results |
138 | 138 |
139 def loaddoc(topic): | 139 def loaddoc(topic): |
140 """Return a delayed loader for help/topic.txt.""" | 140 """Return a delayed loader for help/topic.txt.""" |
141 | 141 |
142 def loader(): | 142 def loader(ui): |
143 docdir = os.path.join(util.datapath, 'help') | 143 docdir = os.path.join(util.datapath, 'help') |
144 path = os.path.join(docdir, topic + ".txt") | 144 path = os.path.join(docdir, topic + ".txt") |
145 doc = gettext(util.readfile(path)) | 145 doc = gettext(util.readfile(path)) |
146 for rewriter in helphooks.get(topic, []): | 146 for rewriter in helphooks.get(topic, []): |
147 doc = rewriter(topic, doc) | 147 doc = rewriter(topic, doc) |
413 | 413 |
414 # description | 414 # description |
415 if not doc: | 415 if not doc: |
416 rst.append(" %s\n" % _("(no help text available)")) | 416 rst.append(" %s\n" % _("(no help text available)")) |
417 if callable(doc): | 417 if callable(doc): |
418 rst += [" %s\n" % l for l in doc().splitlines()] | 418 rst += [" %s\n" % l for l in doc(ui).splitlines()] |
419 | 419 |
420 if not ui.verbose: | 420 if not ui.verbose: |
421 omitted = _('(some details hidden, use --verbose' | 421 omitted = _('(some details hidden, use --verbose' |
422 ' to show complete help)') | 422 ' to show complete help)') |
423 indicateomitted(rst, omitted) | 423 indicateomitted(rst, omitted) |
480 | 480 |
481 | 481 |
482 rst = [] | 482 rst = [] |
483 kw = opts.get('keyword') | 483 kw = opts.get('keyword') |
484 if kw: | 484 if kw: |
485 matches = topicmatch(name) | 485 matches = topicmatch(ui, name) |
486 helpareas = [] | 486 helpareas = [] |
487 if opts.get('extension'): | 487 if opts.get('extension'): |
488 helpareas += [('extensions', _('Extensions'))] | 488 helpareas += [('extensions', _('Extensions'))] |
489 if opts.get('command'): | 489 if opts.get('command'): |
490 helpareas += [('commands', _('Commands'))] | 490 helpareas += [('commands', _('Commands'))] |