diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3063,7 +3063,9 @@ def heads(ui, repo, *branchrevs, **opts) @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 @@ def help_(ui, name=None, unknowncmd=Fals 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 @@ def help_(ui, name=None, unknowncmd=Fals 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: diff --git a/mercurial/help.py b/mercurial/help.py --- a/mercurial/help.py +++ b/mercurial/help.py @@ -69,7 +69,7 @@ def topicmatch(kw): 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__', '')))) diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t --- a/tests/test-debugcomplete.t +++ b/tests/test-debugcomplete.t @@ -250,7 +250,7 @@ Show all commands + options 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