Patchwork dispatch: fix so that --help more reliably shows command help (issue4240)

login
register
mail settings
Submitter Matt Mackall
Date July 31, 2014, 7:37 p.m.
Message ID <1406835420.2899.153.camel@calx>
Download mbox | patch
Permalink /patch/5215/
State Accepted
Headers show

Comments

Matt Mackall - July 31, 2014, 7:37 p.m.
On Tue, 2014-07-22 at 21:07 +0530, Prabhu Gnana Sundar wrote:
> # HG changeset patch
> # User Prabhu Gnana Sundar <pprabhugs@gmail.com>
> # Date 1406011473 -19800
> #      Tue Jul 22 12:14:33 2014 +0530
> # Branch stable
> # Node ID f3157bfd4969cfec2c0f6577841feca6638823b7
> # Parent  a5168eb9b2bc488f42809872d22321a9825bc738
> dispatch: fix so that --help more reliably shows command help (issue4240)
> 
> After hg 3.0, "hg showconfig --help" was showing the configuration man page
> instead of the 'hg help -c showconfig' output.

Thanks for the patch, I'm afraid I had to think about this for a while.
This patch is a bit unfortunate because it special-cases a single
command, and it would be nice to do this generically. This is what I
came up with (note the table in the commit message that lays out the
whole situation):

# HG changeset patch
# User Matt Mackall <mpm@selenic.com>
# Date 1406835091 18000
#      Thu Jul 31 14:31:31 2014 -0500
# Branch stable
# Node ID af15de6775c73b66e4ad08d1cfb084935eb80015
# Parent  2896d450fec495e8f043a68117f40fcf24619d4f
help: always show command help with -h (issue4240)

Old behavior:
              hg help x    hg x -h    hg help -e x  hg help -c x
config        topic        topic (!)  -             cmd
showconfig    cmd          topic (!)  -             cmd
rebase        cmd          cmd        ext           cmd

New behavior:
              hg help x    hg x -h    hg help -e x  hg help -c x
config        topic        cmd        -             cmd
showconfig    cmd          cmd        -             cmd
rebase        cmd          cmd        ext           cmd

Patch

diff -r 2896d450fec4 -r af15de6775c7 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Fri Aug 01 02:14:24 2014 +0900
+++ b/mercurial/dispatch.py	Thu Jul 31 14:31:31 2014 -0500
@@ -766,7 +766,7 @@ 
     if options['version']:
         return commands.version_(ui)
     if options['help']:
-        return commands.help_(ui, cmd)
+        return commands.help_(ui, cmd, command=True)
     elif not cmd:
         return commands.help_(ui, 'shortlist')
 
diff -r 2896d450fec4 -r af15de6775c7 tests/test-help.t
--- a/tests/test-help.t	Fri Aug 01 02:14:24 2014 +0900
+++ b/tests/test-help.t	Thu Jul 31 14:31:31 2014 -0500
@@ -862,6 +862,17 @@ 
   *"hg -v help debugoptDEP"* (glob)
 #endif
 
+Test commands that collide with topics (issue4240)
+
+  $ hg config -hq
+  hg config [-u] [NAME]...
+  
+  show combined config settings from all hgrc files
+  $ hg showconfig -hq
+  hg config [-u] [NAME]...
+  
+  show combined config settings from all hgrc files
+
 Test a help topic
 
   $ hg help revs