Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/help.py @ 40490:444861dc1e55
help: displaying documented aliases by default
This makes aliases be displayed in "hg help" when they have a :doc config
entry, and also allows them to be assigned to a category with :category.
Differential Revision: https://phab.mercurial-scm.org/D5087
author | rdamazio@google.com |
---|---|
date | Thu, 18 Oct 2018 19:57:05 -0700 |
parents | 1ddd202c47d9 |
children | dce0e0f78f0f |
comparison
equal
deleted
inserted
replaced
40489:1ddd202c47d9 | 40490:444861dc1e55 |
---|---|
187 def indicateomitted(rst, omitted, notomitted=None): | 187 def indicateomitted(rst, omitted, notomitted=None): |
188 rst.append('\n\n.. container:: omitted\n\n %s\n\n' % omitted) | 188 rst.append('\n\n.. container:: omitted\n\n %s\n\n' % omitted) |
189 if notomitted: | 189 if notomitted: |
190 rst.append('\n\n.. container:: notomitted\n\n %s\n\n' % notomitted) | 190 rst.append('\n\n.. container:: notomitted\n\n %s\n\n' % notomitted) |
191 | 191 |
192 def filtercmd(ui, cmd, kw, doc): | 192 def filtercmd(ui, cmd, func, kw, doc): |
193 if not ui.debugflag and cmd.startswith("debug") and kw != "debug": | 193 if not ui.debugflag and cmd.startswith("debug") and kw != "debug": |
194 # Debug command, and user is not looking for those. | |
194 return True | 195 return True |
195 if not ui.verbose and doc and any(w in doc for w in _exclkeywords): | 196 if not ui.verbose: |
197 if not kw and not doc: | |
198 # Command had no documentation, no point in showing it by default. | |
199 return True | |
200 if getattr(func, 'alias', False) and not getattr(func, 'owndoc', False): | |
201 # Alias didn't have its own documentation. | |
202 return True | |
203 if doc and any(w in doc for w in _exclkeywords): | |
204 # Documentation has excluded keywords. | |
205 return True | |
206 if kw == "shortlist" and not getattr(func, 'helpbasic', False): | |
207 # We're presenting the short list but the command is not basic. | |
196 return True | 208 return True |
197 if ui.configbool('help', 'hidden-command.%s' % cmd): | 209 if ui.configbool('help', 'hidden-command.%s' % cmd): |
210 # Configuration explicitly hides the command. | |
198 return True | 211 return True |
199 return False | 212 return False |
200 | 213 |
201 def filtertopic(ui, topic): | 214 def filtertopic(ui, topic): |
202 return ui.configbool('help', 'hidden-topic.%s' % topic, False) | 215 return ui.configbool('help', 'hidden-topic.%s' % topic, False) |
228 if len(entry) == 3: | 241 if len(entry) == 3: |
229 summary = entry[2] | 242 summary = entry[2] |
230 else: | 243 else: |
231 summary = '' | 244 summary = '' |
232 # translate docs *before* searching there | 245 # translate docs *before* searching there |
233 docs = _(pycompat.getdoc(entry[0])) or '' | 246 func = entry[0] |
247 docs = _(pycompat.getdoc(func)) or '' | |
234 if kw in cmd or lowercontains(summary) or lowercontains(docs): | 248 if kw in cmd or lowercontains(summary) or lowercontains(docs): |
235 doclines = docs.splitlines() | 249 doclines = docs.splitlines() |
236 if doclines: | 250 if doclines: |
237 summary = doclines[0] | 251 summary = doclines[0] |
238 cmdname = cmdutil.parsealiases(cmd)[0] | 252 cmdname = cmdutil.parsealiases(cmd)[0] |
239 if filtercmd(ui, cmdname, kw, docs): | 253 if filtercmd(ui, cmdname, func, kw, docs): |
240 continue | 254 continue |
241 results['commands'].append((cmdname, summary)) | 255 results['commands'].append((cmdname, summary)) |
242 for name, docs in itertools.chain( | 256 for name, docs in itertools.chain( |
243 extensions.enabled(False).iteritems(), | 257 extensions.enabled(False).iteritems(), |
244 extensions.disabled().iteritems()): | 258 extensions.disabled().iteritems()): |
254 # debug message would be printed in extensions.load() | 268 # debug message would be printed in extensions.load() |
255 continue | 269 continue |
256 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems(): | 270 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems(): |
257 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])): | 271 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])): |
258 cmdname = cmdutil.parsealiases(cmd)[0] | 272 cmdname = cmdutil.parsealiases(cmd)[0] |
259 cmddoc = pycompat.getdoc(entry[0]) | 273 func = entry[0] |
274 cmddoc = pycompat.getdoc(func) | |
260 if cmddoc: | 275 if cmddoc: |
261 cmddoc = gettext(cmddoc).splitlines()[0] | 276 cmddoc = gettext(cmddoc).splitlines()[0] |
262 else: | 277 else: |
263 cmddoc = _('(no help text available)') | 278 cmddoc = _('(no help text available)') |
264 if filtercmd(ui, cmdname, kw, cmddoc): | 279 if filtercmd(ui, cmdname, func, kw, cmddoc): |
265 continue | 280 continue |
266 results['extensioncommands'].append((cmdname, cmddoc)) | 281 results['extensioncommands'].append((cmdname, cmddoc)) |
267 return results | 282 return results |
268 | 283 |
269 def loaddoc(topic, subdir=None): | 284 def loaddoc(topic, subdir=None): |
523 f = fs[0] | 538 f = fs[0] |
524 syns[f] = ', '.join(fs) | 539 syns[f] = ', '.join(fs) |
525 func = e[0] | 540 func = e[0] |
526 if select and not select(f): | 541 if select and not select(f): |
527 continue | 542 continue |
543 # Only list built-in commands (defined in commands.py) and aliases | |
544 # (defined in dispatch.py), but not any other extensions. | |
545 # We don't want a circular dependency between this file and | |
546 # dispatch, so reference that by name. | |
547 # TODO(rdamazio): Just show commands from all extensions. | |
528 if (not select and name != 'shortlist' and | 548 if (not select and name != 'shortlist' and |
529 func.__module__ != commands.__name__): | 549 func.__module__ != commands.__name__ and |
550 func.__module__ != 'mercurial.dispatch'): | |
530 continue | 551 continue |
531 if name == "shortlist": | |
532 if not getattr(func, 'helpbasic', False): | |
533 continue | |
534 doc = pycompat.getdoc(func) | 552 doc = pycompat.getdoc(func) |
535 if filtercmd(ui, f, name, doc): | 553 if filtercmd(ui, f, func, name, doc): |
536 continue | 554 continue |
537 doc = gettext(doc) | 555 doc = gettext(doc) |
538 if not doc: | 556 if not doc: |
539 doc = _("(no help text available)") | 557 doc = _("(no help text available)") |
540 h[f] = doc.splitlines()[0].rstrip() | 558 h[f] = doc.splitlines()[0].rstrip() |