##// END OF EJS Templates
help: displaying documented aliases by default...
rdamazio@google.com -
r40450:444861dc default
parent child Browse files
Show More
@@ -37,6 +37,7 b' from . import ('
37 37 hook,
38 38 profiling,
39 39 pycompat,
40 registrar,
40 41 scmutil,
41 42 ui as uimod,
42 43 util,
@@ -503,6 +504,7 b' class cmdalias(object):'
503 504 return ui.system(cmd, environ=env,
504 505 blockedtag='alias_%s' % self.name)
505 506 self.fn = fn
507 self.alias = True
506 508 self._populatehelp(ui, name, shdef, self.fn)
507 509 return
508 510
@@ -530,6 +532,7 b' class cmdalias(object):'
530 532 self.fn, self.opts = tableentry
531 533 cmdhelp = None
532 534
535 self.alias = True
533 536 self._populatehelp(ui, name, cmd, self.fn, cmdhelp)
534 537
535 538 except error.UnknownCommand:
@@ -543,7 +546,7 b' class cmdalias(object):'
543 546 def _populatehelp(self, ui, name, cmd, fn, defaulthelp=None):
544 547 # confine strings to be passed to i18n.gettext()
545 548 cfg = {}
546 for k in ('doc', 'help'):
549 for k in ('doc', 'help', 'category'):
547 550 v = ui.config('alias', '%s:%s' % (name, k), None)
548 551 if v is None:
549 552 continue
@@ -558,11 +561,14 b' class cmdalias(object):'
558 561 # drop prefix in old-style help lines so hg shows the alias
559 562 self.help = self.help[4 + len(cmd):]
560 563
564 self.owndoc = 'doc' in cfg
561 565 doc = cfg.get('doc', pycompat.getdoc(fn))
562 566 if doc is not None:
563 567 doc = pycompat.sysstr(doc)
564 568 self.__doc__ = doc
565 569
570 self.helpcategory = cfg.get('category', registrar.command.CATEGORY_NONE)
571
566 572 @property
567 573 def args(self):
568 574 args = pycompat.maplist(util.expandpath, self.givenargs)
@@ -613,6 +619,7 b' class lazyaliasentry(object):'
613 619 self.definition = definition
614 620 self.cmdtable = cmdtable.copy()
615 621 self.source = source
622 self.alias = True
616 623
617 624 @util.propertycache
618 625 def _aliasdef(self):
@@ -189,12 +189,25 b' def indicateomitted(rst, omitted, notomi'
189 189 if notomitted:
190 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 193 if not ui.debugflag and cmd.startswith("debug") and kw != "debug":
194 # Debug command, and user is not looking for those.
194 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 208 return True
197 209 if ui.configbool('help', 'hidden-command.%s' % cmd):
210 # Configuration explicitly hides the command.
198 211 return True
199 212 return False
200 213
@@ -230,13 +243,14 b' def topicmatch(ui, commands, kw):'
230 243 else:
231 244 summary = ''
232 245 # translate docs *before* searching there
233 docs = _(pycompat.getdoc(entry[0])) or ''
246 func = entry[0]
247 docs = _(pycompat.getdoc(func)) or ''
234 248 if kw in cmd or lowercontains(summary) or lowercontains(docs):
235 249 doclines = docs.splitlines()
236 250 if doclines:
237 251 summary = doclines[0]
238 252 cmdname = cmdutil.parsealiases(cmd)[0]
239 if filtercmd(ui, cmdname, kw, docs):
253 if filtercmd(ui, cmdname, func, kw, docs):
240 254 continue
241 255 results['commands'].append((cmdname, summary))
242 256 for name, docs in itertools.chain(
@@ -256,12 +270,13 b' def topicmatch(ui, commands, kw):'
256 270 for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
257 271 if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
258 272 cmdname = cmdutil.parsealiases(cmd)[0]
259 cmddoc = pycompat.getdoc(entry[0])
273 func = entry[0]
274 cmddoc = pycompat.getdoc(func)
260 275 if cmddoc:
261 276 cmddoc = gettext(cmddoc).splitlines()[0]
262 277 else:
263 278 cmddoc = _('(no help text available)')
264 if filtercmd(ui, cmdname, kw, cmddoc):
279 if filtercmd(ui, cmdname, func, kw, cmddoc):
265 280 continue
266 281 results['extensioncommands'].append((cmdname, cmddoc))
267 282 return results
@@ -525,14 +540,17 b' def help_(ui, commands, name, unknowncmd'
525 540 func = e[0]
526 541 if select and not select(f):
527 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 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 551 continue
531 if name == "shortlist":
532 if not getattr(func, 'helpbasic', False):
533 continue
534 552 doc = pycompat.getdoc(func)
535 if filtercmd(ui, f, name, doc):
553 if filtercmd(ui, f, func, name, doc):
536 554 continue
537 555 doc = gettext(doc)
538 556 if not doc:
@@ -169,6 +169,10 b' class command(_funcregistrarbase):'
169 169 """
170 170
171 171 # Command categories for grouping them in help output.
172 # These can also be specified for aliases, like:
173 # [alias]
174 # myalias = something
175 # myalias:category = repo
172 176 CATEGORY_REPO_CREATION = 'repo'
173 177 CATEGORY_REMOTE_REPO_MANAGEMENT = 'remote'
174 178 CATEGORY_COMMITTING = 'commit'
@@ -68,17 +68,17 b' basic'
68 68 help
69 69
70 70 $ hg help -c | grep myinit
71 myinit This is my documented alias for init.
71 myinit This is my documented alias for init.
72 72 $ hg help -c | grep mycommit
73 mycommit This is my alias with only doc.
73 mycommit This is my alias with only doc.
74 74 $ hg help -c | grep cleanstatus
75 cleanstatus show changed files in the working directory
75 [1]
76 76 $ hg help -c | grep lognull
77 lognull Logs the null rev
77 lognull Logs the null rev
78 78 $ hg help -c | grep dln
79 dln Logs the null rev
79 [1]
80 80 $ hg help -c | grep recursivedoc
81 recursivedoc Logs the null rev in debug mode
81 recursivedoc Logs the null rev in debug mode
82 82 $ hg help myinit
83 83 hg myinit [OPTIONS] [BLA] [BLE]
84 84
@@ -602,7 +602,7 b' command provided extension, should be ab'
602 602 help for a shell alias
603 603
604 604 $ hg help -c | grep rebate
605 rebate This is my alias which just prints something.
605 rebate This is my alias which just prints something.
606 606 $ hg help rebate
607 607 hg rebate [MYARGS]
608 608
@@ -823,6 +823,9 b' this is a section and erroring out weird'
823 823 > def uisetup(ui):
824 824 > ui.setconfig(b'alias', b'shellalias', b'!echo hi', b'helpext')
825 825 > ui.setconfig(b'alias', b'hgalias', b'summary', b'helpext')
826 > ui.setconfig(b'alias', b'hgalias:doc', b'My doc', b'helpext')
827 > ui.setconfig(b'alias', b'hgalias:category', b'navigation', b'helpext')
828 > ui.setconfig(b'alias', b'hgaliasnodoc', b'summary', b'helpext')
826 829 >
827 830 > EOF
828 831 $ echo '[extensions]' >> $HGRCPATH
@@ -830,11 +833,28 b' this is a section and erroring out weird'
830 833
831 834 Test for aliases
832 835
836 $ hg help | grep hgalias
837 hgalias My doc
838
833 839 $ hg help hgalias
834 840 hg hgalias [--remote]
835 841
836 842 alias for: hg summary
837 843
844 My doc
845
846 defined by: helpext
847
848 options:
849
850 --remote check for push and pull
851
852 (some details hidden, use --verbose to show complete help)
853 $ hg help hgaliasnodoc
854 hg hgaliasnodoc [--remote]
855
856 alias for: hg summary
857
838 858 summarize working directory state
839 859
840 860 This generates a brief summary of the working directory state, including
@@ -947,6 +967,7 b' Test that default list of commands omits'
947 967
948 968 bisect subdivision search of changesets
949 969 heads show branch heads
970 hgalias My doc
950 971 identify identify the working directory or specified revision
951 972 log show revision history of entire repository or files
952 973
@@ -2662,6 +2683,13 b' Dish up an empty repo; serve it cold.'
2662 2683 hgalias
2663 2684 </a>
2664 2685 </td><td>
2686 My doc
2687 </td></tr>
2688 <tr><td>
2689 <a href="/help/hgaliasnodoc">
2690 hgaliasnodoc
2691 </a>
2692 </td><td>
2665 2693 summarize working directory state
2666 2694 </td></tr>
2667 2695 <tr><td>
General Comments 0
You need to be logged in to leave comments. Login now