help: fix help -c/help -e/help -k
authortimeless <timeless@mozdev.org>
Wed, 09 Dec 2015 05:56:54 +0000
changeset 27325 eadbbd14bdc1
parent 27324 5456374561a7
child 27326 ee2d7b5daa8a
help: fix help -c/help -e/help -k Before, hg help -c was the same as hg help, now it only shows commands. Before, hg help -e was the same as hg help, now it only shows extensions. Before, hg help -k crashed, now it shows all topics.
mercurial/dispatch.py
mercurial/help.py
tests/test-help.t
--- a/mercurial/dispatch.py	Wed Dec 09 19:09:35 2015 +0000
+++ b/mercurial/dispatch.py	Wed Dec 09 05:56:54 2015 +0000
@@ -854,7 +854,7 @@
     if options['version']:
         return commands.version_(ui)
     if options['help']:
-        return commands.help_(ui, cmd, command=True)
+        return commands.help_(ui, cmd, command=cmd is not None)
     elif not cmd:
         return commands.help_(ui, 'shortlist')
 
--- a/mercurial/help.py	Wed Dec 09 19:09:35 2015 +0000
+++ b/mercurial/help.py	Wed Dec 09 05:56:54 2015 +0000
@@ -328,7 +328,7 @@
         return rst
 
 
-    def helplist(select=None):
+    def helplist(select=None, **opts):
         # list of commands
         if name == "shortlist":
             header = _('basic commands:\n\n')
@@ -374,7 +374,9 @@
             else:
                 rst.append(' :%s: %s\n' % (f, h[f]))
 
-        if not name:
+        ex = opts.get
+        anyopts = (ex('keyword') or not (ex('command') or ex('extension')))
+        if not name and anyopts:
             exts = listexts(_('enabled extensions:'), extensions.enabled())
             if exts:
                 rst.append('\n')
@@ -491,8 +493,8 @@
 
     rst = []
     kw = opts.get('keyword')
-    if kw:
-        matches = topicmatch(ui, name)
+    if kw or name is None and any(opts[o] for o in opts):
+        matches = topicmatch(ui, name or '')
         helpareas = []
         if opts.get('extension'):
             helpareas += [('extensions', _('Extensions'))]
@@ -539,6 +541,6 @@
         # program name
         if not ui.quiet:
             rst = [_("Mercurial Distributed SCM\n"), '\n']
-        rst.extend(helplist())
+        rst.extend(helplist(None, **opts))
 
     return ''.join(rst)
--- a/tests/test-help.t	Wed Dec 09 19:09:35 2015 +0000
+++ b/tests/test-help.t	Wed Dec 09 05:56:54 2015 +0000
@@ -1043,16 +1043,25 @@
 
 help -c should only show debug --debug
 
-  $ hg help -c --debug|grep debug|wc -l|grep '^\s*0\s*$'
+  $ hg help -c --debug|egrep debug|wc -l|egrep '^\s*0\s*$'
   [1]
 
 help -c should only show deprecated for -v
 
-  $ hg help -c -v|grep DEPRECATED|wc -l|grep '^\s*0\s*$'
+  $ hg help -c -v|egrep DEPRECATED|wc -l|egrep '^\s*0\s*$'
   [1]
 
 Test -e / -c / -k combinations
 
+  $ hg help -c|egrep '^\S|debug'
+  Commands:
+  $ hg help -e|egrep '^\S'
+  Extensions:
+  $ hg help -k|egrep '^\S'
+  Topics:
+  Commands:
+  Extensions:
+  Extension Commands:
   $ hg help -c schemes
   abort: no such help topic: schemes
   (try "hg help --keyword schemes")