[PATCH 2 of 2] add hint when displaying help for command with same name as extension

Henri Wiechers hwiechers at gmail.com
Fri Jan 22 09:48:57 CST 2010


# HG changeset patch
# User Henri Wiechers <hwiechers at gmail.com>
# Date 1264175070 -7200
# Node ID 6c65685b34e22c58f2b31bfca3aec9e887ac9663
# Parent  9e140e05f7c792c2f44d6cef0992fead936442b9
add hint when displaying help for command with same name as extension

diff -r 9e140e05f7c7 -r 6c65685b34e2 mercurial/commands.py
--- a/mercurial/commands.py	Wed Jan 20 20:24:20 2010 +0200
+++ b/mercurial/commands.py	Fri Jan 22 17:44:30 2010 +0200
@@ -1521,6 +1521,18 @@
 
             addglobalopts(False)
 
+        writeopts()
+
+        if not ui.quiet:
+            ext = None
+            try:
+                ext = extensions.find(name)
+            except KeyError:
+                pass
+            if ext:
+                ui.write(_('use "hg help -e %s" to see overall help for the ' 
+                           'extension\n') % name)
+
     def helplist(header, select=None):
         h = {}
         cmds = {}
@@ -1602,6 +1614,32 @@
         modcmds = set([c.split('|', 1)[0] for c in ct])
         helplist(_('list of commands:\n\n'), modcmds.__contains__)
 
+    def writeopts():
+        opt_output = []
+        for title, options in option_lists:
+            opt_output.append(("\n%s" % title, None))
+            for shortopt, longopt, default, desc in options:
+                if _("DEPRECATED") in desc and not ui.verbose: continue
+                opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
+                                              longopt and " --%s" % longopt),
+                                   "%s%s" % (desc,
+                                             default
+                                             and _(" (default: %s)") % default
+                                             or "")))
+
+        if opt_output:
+            opts_len = max([len(line[0]) for line in opt_output if line[1]] 
+                           or [0])
+            for first, second in opt_output:
+                if second:
+                    second = util.wrap(second, opts_len + 3)
+                    ui.write(" %-*s  %s\n" % (opts_len, first, second))
+                else:
+                    ui.write("%s\n" % first)
+        
+        # clear the option list
+        del option_lists[:]
+
     if name and name != 'shortlist':
         helpfns = (helptopic, helpcmd, helpext)
         if opts.get('extension'):
@@ -1639,19 +1677,6 @@
             if text:
                 ui.write("\n%s\n" % minirst.format(text, textwidth))
 
-    # list all option lists
-    opt_output = []
-    for title, options in option_lists:
-        opt_output.append(("\n%s" % title, None))
-        for shortopt, longopt, default, desc in options:
-            if _("DEPRECATED") in desc and not ui.verbose: continue
-            opt_output.append(("%2s%s" % (shortopt and "-%s" % shortopt,
-                                          longopt and " --%s" % longopt),
-                               "%s%s" % (desc,
-                                         default
-                                         and _(" (default: %s)") % default
-                                         or "")))
-
     if not name:
         ui.write(_("\nadditional help topics:\n\n"))
         topics = []
@@ -1661,14 +1686,7 @@
         for t, desc in topics:
             ui.write(" %-*s  %s\n" % (topics_len, t, desc))
 
-    if opt_output:
-        opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
-        for first, second in opt_output:
-            if second:
-                second = util.wrap(second, opts_len + 3)
-                ui.write(" %-*s  %s\n" % (opts_len, first, second))
-            else:
-                ui.write("%s\n" % first)
+    writeopts()
 
 def identify(ui, repo, source=None,
              rev=None, num=None, id=None, branch=None, tags=None):
diff -r 9e140e05f7c7 -r 6c65685b34e2 tests/test-convert.out
--- a/tests/test-convert.out	Wed Jan 20 20:24:20 2010 +0200
+++ b/tests/test-convert.out	Fri Jan 22 17:44:30 2010 +0200
@@ -221,6 +221,7 @@
     --sourcesort   preserve source changesets order
 
 use "hg -v help convert" to show global options
+use "hg help -e convert" to see overall help for the extension
 adding a
 assuming destination a-hg
 initializing destination a-hg repository
diff -r 9e140e05f7c7 -r 6c65685b34e2 tests/test-extension
--- a/tests/test-extension	Wed Jan 20 20:24:20 2010 +0200
+++ b/tests/test-extension	Fri Jan 22 17:44:30 2010 +0200
@@ -170,7 +170,9 @@
 EOF
 exthelppath=`pwd`/exthelp.py
 echo "exthelp=$exthelppath" >> $HGRCPATH
-echo % should show help for exthelp command
+echo % should show help for exthelp command and -e message
 hg help exthelp
+echo % should show help for exthelp command and not -e message
+hg -q help exthelp  
 echo % should show help for exthelp extension
 hg help -e exthelp
diff -r 9e140e05f7c7 -r 6c65685b34e2 tests/test-extension.out
--- a/tests/test-extension.out	Wed Jan 20 20:24:20 2010 +0200
+++ b/tests/test-extension.out	Fri Jan 22 17:44:30 2010 +0200
@@ -97,12 +97,17 @@
 debugissue811
 mq
 % test limiting help to extension topics
-% should show help for exthelp command
+% should show help for exthelp command and -e message
 hg exthelp
 
 command help text
 
 use "hg -v help exthelp" to show global options
+use "hg help -e exthelp" to see overall help for the extension
+% should show help for exthelp command and not -e message
+hg exthelp
+
+command help text
 % should show help for exthelp extension
 exthelp extension - extension help text
 
diff -r 9e140e05f7c7 -r 6c65685b34e2 tests/test-rebase-parameters.out
--- a/tests/test-rebase-parameters.out	Wed Jan 20 20:24:20 2010 +0200
+++ b/tests/test-rebase-parameters.out	Fri Jan 22 17:44:30 2010 +0200
@@ -27,6 +27,7 @@
     --template      display with template
 
 use "hg -v help rebase" to show global options
+use "hg help -e rebase" to see overall help for the extension
 
 % Use continue and collapse
 hg rebase: cannot use collapse with continue or abort
@@ -55,6 +56,7 @@
     --template      display with template
 
 use "hg -v help rebase" to show global options
+use "hg help -e rebase" to see overall help for the extension
 
 % Use continue/abort and dest/source
 hg rebase: abort and continue do not allow specifying revisions
@@ -83,6 +85,7 @@
     --template      display with template
 
 use "hg -v help rebase" to show global options
+use "hg help -e rebase" to see overall help for the extension
 
 % Use source and base
 hg rebase: cannot specify both a revision and a base
@@ -111,6 +114,7 @@
     --template      display with template
 
 use "hg -v help rebase" to show global options
+use "hg help -e rebase" to see overall help for the extension
 
 % Rebase with no arguments - from current
 nothing to rebase
diff -r 9e140e05f7c7 -r 6c65685b34e2 tests/test-record.out
--- a/tests/test-record.out	Wed Jan 20 20:24:20 2010 +0200
+++ b/tests/test-record.out	Fri Jan 22 17:44:30 2010 +0200
@@ -36,6 +36,7 @@
  -u --user          record the specified user as committer
 
 use "hg -v help record" to show global options
+use "hg help -e record" to see overall help for the extension
 % select no files
 diff --git a/empty-rw b/empty-rw
 new file mode 100644


More information about the Mercurial-devel mailing list