help: add -c/--command flag to only show command help (issue2799)
authorMartin Geisler <mg@aragost.com>
Tue, 10 May 2011 14:42:53 +0200
changeset 14286 005a540e9aee
parent 14285 aa64a87b493d
child 14287 7c231754a621
help: add -c/--command flag to only show command help (issue2799)
mercurial/commands.py
mercurial/dispatch.py
tests/test-bad-extension.t
tests/test-debugcomplete.t
tests/test-extension.t
--- a/mercurial/commands.py	Tue May 10 13:19:05 2011 +0200
+++ b/mercurial/commands.py	Tue May 10 14:42:53 2011 +0200
@@ -2293,6 +2293,12 @@
 
         ui.write("%s\n\n" % header)
         ui.write("%s\n" % minirst.format(doc, textwidth, indent=4))
+        try:
+            cmdutil.findcmd(name, table)
+            ui.write(_('\nuse "hg help -c %s" to see help for '
+                       'the %s command\n') % (name, name))
+        except error.UnknownCommand:
+            pass
 
     def helpext(name):
         try:
@@ -2346,6 +2352,8 @@
             queries = (helpextcmd,)
         elif opts.get('extension'):
             queries = (helpext,)
+        elif opts.get('command'):
+            queries = (helpcmd,)
         else:
             queries = (helptopic, helpcmd, helpext, helpextcmd)
         for f in queries:
@@ -4720,8 +4728,9 @@
          ] + templateopts,
          _('[-ac] [-r STARTREV] [REV]...')),
     "help": (help_,
-        [('e', 'extension', None, _('show only help for extensions'))],
-        _('[-e] [TOPIC]')),
+        [('e', 'extension', None, _('show only help for extensions')),
+         ('c', 'command', None, _('show only help for commands'))],
+        _('[-ec] [TOPIC]')),
     "identify|id":
         (identify,
          [('r', 'rev', '',
--- a/mercurial/dispatch.py	Tue May 10 13:19:05 2011 +0200
+++ b/mercurial/dispatch.py	Tue May 10 14:42:53 2011 +0200
@@ -90,7 +90,7 @@
     except error.CommandError, inst:
         if inst.args[0]:
             ui.warn(_("hg %s: %s\n") % (inst.args[0], inst.args[1]))
-            commands.help_(ui, inst.args[0], full=False)
+            commands.help_(ui, inst.args[0], full=False, command=True)
         else:
             ui.warn(_("hg: %s\n") % inst.args[1])
             commands.help_(ui, 'shortlist')
--- a/tests/test-bad-extension.t	Tue May 10 13:19:05 2011 +0200
+++ b/tests/test-bad-extension.t	Tue May 10 14:42:53 2011 +0200
@@ -10,6 +10,6 @@
   $ hg -q help help
   *** failed to import extension badext from $TESTTMP/badext.py: bit bucket overflow
   *** failed to import extension badext2: No module named badext2
-  hg help [-e] [TOPIC]
+  hg help [-ec] [TOPIC]
   
   show help for a given topic or a help overview
--- a/tests/test-debugcomplete.t	Tue May 10 13:19:05 2011 +0200
+++ b/tests/test-debugcomplete.t	Tue May 10 14:42:53 2011 +0200
@@ -239,7 +239,7 @@
   debugwireargs: three, four, five, ssh, remotecmd, insecure
   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
+  help: extension, command
   identify: rev, num, id, branch, tags, bookmarks
   import: strip, base, force, no-commit, 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
--- a/tests/test-extension.t	Tue May 10 13:19:05 2011 +0200
+++ b/tests/test-extension.t	Tue May 10 14:42:53 2011 +0200
@@ -329,6 +329,59 @@
 
   $ echo 'extdiff = !' >> $HGRCPATH
 
+Test help topic with same name as extension
+
+  $ cat > multirevs.py <<EOF
+  > from mercurial import commands
+  > """multirevs extension
+  > Big multi-line module docstring."""
+  > def multirevs(ui, repo, arg, *args, **opts):
+  >     """multirevs command"""
+  >     pass
+  > cmdtable = {
+  >    "multirevs": (multirevs, [], 'ARG')
+  > }
+  > commands.norepo += ' multirevs'
+  > EOF
+  $ echo "multirevs = multirevs.py" >> $HGRCPATH
+
+  $ hg help multirevs
+  Specifying Multiple Revisions
+  
+      When Mercurial accepts more than one revision, they may be specified
+      individually, or provided as a topologically continuous range, separated
+      by the ":" character.
+  
+      The syntax of range notation is [BEGIN]:[END], where BEGIN and END are
+      revision identifiers. Both BEGIN and END are optional. If BEGIN is not
+      specified, it defaults to revision number 0. If END is not specified, it
+      defaults to the tip. The range ":" thus means "all revisions".
+  
+      If BEGIN is greater than END, revisions are treated in reverse order.
+  
+      A range acts as a closed interval. This means that a range of 3:5 gives 3,
+      4 and 5. Similarly, a range of 9:6 gives 9, 8, 7, and 6.
+  
+  use "hg help -c multirevs" to see help for the multirevs command
+
+  $ hg help -c multirevs
+  hg multirevs ARG
+  
+  multirevs command
+  
+  use "hg -v help multirevs" to show global options
+
+  $ hg multirevs
+  hg multirevs: invalid arguments
+  hg multirevs ARG
+  
+  multirevs command
+  
+  use "hg help multirevs" to show the full help text
+  [255]
+
+  $ echo "multirevs = !" >> $HGRCPATH
+
 Issue811: Problem loading extensions twice (by site and by user)
 
   $ debugpath=`pwd`/debugissue811.py