help: add --keyword (-k) for searching help
authorAugie Fackler <raf@durin42.com>
Sun, 13 May 2012 06:03:11 -0500
changeset 16711 497deec204d1
parent 16710 a17983680f12
child 16712 846ed7a730db
help: add --keyword (-k) for searching help
mercurial/commands.py
mercurial/help.py
tests/test-debugcomplete.t
--- a/mercurial/commands.py	Sun May 13 04:27:08 2012 -0500
+++ b/mercurial/commands.py	Sun May 13 06:03:11 2012 -0500
@@ -3063,7 +3063,9 @@
 
 @command('help',
     [('e', 'extension', None, _('show only help for extensions')),
-     ('c', 'command', None, _('show only help for commands'))],
+     ('c', 'command', None, _('show only help for commands')),
+     ('k', 'keyword', '', _('show topics matching keyword')),
+     ],
     _('[-ec] [TOPIC]'))
 def help_(ui, name=None, unknowncmd=False, full=True, **opts):
     """show help for a given topic or a help overview
@@ -3309,7 +3311,7 @@
             doc = doc()
 
         ui.write("%s\n\n" % header)
-        ui.write("%s" % minirst.format(doc, textwidth, indent=4))
+        ui.write(minirst.format(doc, textwidth, indent=4))
         try:
             cmdutil.findcmd(name, table)
             ui.write(_('\nuse "hg help -c %s" to see help for '
@@ -3359,6 +3361,18 @@
         ui.write(_('use "hg help extensions" for information on enabling '
                    'extensions\n'))
 
+    kw = opts.get('keyword')
+    if kw:
+        matches = help.topicmatch(kw)
+        for t, title in (('topics', _('Topics')),
+                         ('commands', _('Commands')),
+                         ('extensions', _('Extensions')),
+                         ('extensioncommands', _('Extension Commands'))):
+            if matches[t]:
+                ui.write('%s:\n' % title)
+                ui.write(minirst.format(minirst.maketable(matches[t])))
+        return
+
     if name and name != 'shortlist':
         i = None
         if unknowncmd:
--- a/mercurial/help.py	Sun May 13 04:27:08 2012 -0500
+++ b/mercurial/help.py	Sun May 13 06:03:11 2012 -0500
@@ -69,7 +69,7 @@
         if lowercontains(name) or lowercontains(docs):
             results['extensions'].append((name, _(docs).splitlines()[0]))
         for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
-            if kw in cmd or lowercontains(entry[2]):
+            if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
                 cmdname = cmd.split('|')[0].lstrip('^')
                 results['extensioncommands'].append(
                     (cmdname, _(getattr(cmd, '__doc__', ''))))
--- a/tests/test-debugcomplete.t	Sun May 13 04:27:08 2012 -0500
+++ b/tests/test-debugcomplete.t	Sun May 13 06:03:11 2012 -0500
@@ -250,7 +250,7 @@
   graft: continue, edit, log, currentdate, currentuser, date, user, tool, dry-run
   grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude
   heads: rev, topo, active, closed, style, template
-  help: extension, command
+  help: extension, command, keyword
   identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure
   import: strip, base, edit, force, no-commit, bypass, exact, import-branch, message, logfile, date, user, similarity
   incoming: force, newest-first, bundle, rev, bookmarks, branch, patch, git, limit, no-merges, stat, style, template, ssh, remotecmd, insecure, subrepos