[PATCH 1 of 2] add -e/--extension switch to help command to display extension help text only

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


# HG changeset patch
# User Henri Wiechers <hwiechers at gmail.com>
# Date 1264011860 -7200
# Node ID 9e140e05f7c792c2f44d6cef0992fead936442b9
# Parent  c2e27f7966a7a6ba41b2c593a1f258467b8f643b
add -e/--extension switch to help command to display extension help text only

diff -r c2e27f7966a7 -r 9e140e05f7c7 mercurial/commands.py
--- a/mercurial/commands.py	Wed Jan 20 16:58:48 2010 +0100
+++ b/mercurial/commands.py	Wed Jan 20 20:24:20 2010 +0200
@@ -1446,7 +1446,7 @@
         displayer.show(repo[n])
     displayer.close()
 
-def help_(ui, name=None, with_version=False):
+def help_(ui, name=None, with_version=False, **opts):
     """show help for a given topic or a help overview
 
     With no arguments, print a list of commands with short help messages.
@@ -1603,8 +1603,12 @@
         helplist(_('list of commands:\n\n'), modcmds.__contains__)
 
     if name and name != 'shortlist':
+        helpfns = (helptopic, helpcmd, helpext)
+        if opts.get('extension'):
+            helpfns = (helpext,)
+
         i = None
-        for f in (helptopic, helpcmd, helpext):
+        for f in helpfns:
             try:
                 f(name)
                 i = None
@@ -3482,7 +3486,9 @@
            _('show normal and closed branch heads')),
          ] + templateopts,
          _('[-ac] [-r STARTREV] [REV]...')),
-    "help": (help_, [], _('[TOPIC]')),
+    "help": (help_,
+        [('e', 'extension', None, _('show only help for extensions'))],
+        _('[-e] [TOPIC]')),
     "identify|id":
         (identify,
          [('r', 'rev', '', _('identify the specified revision')),
diff -r c2e27f7966a7 -r 9e140e05f7c7 tests/test-bad-extension.out
--- a/tests/test-bad-extension.out	Wed Jan 20 16:58:48 2010 +0100
+++ b/tests/test-bad-extension.out	Wed Jan 20 20:24:20 2010 +0200
@@ -1,5 +1,5 @@
 *** failed to import extension badext from .../badext.py: bit bucket overflow
 *** failed to import extension badext2: No module named badext2
-hg help [TOPIC]
+hg help [-e] [TOPIC]
 
 show help for a given topic or a help overview
diff -r c2e27f7966a7 -r 9e140e05f7c7 tests/test-debugcomplete.out
--- a/tests/test-debugcomplete.out	Wed Jan 20 16:58:48 2010 +0100
+++ b/tests/test-debugcomplete.out	Wed Jan 20 20:24:20 2010 +0200
@@ -207,7 +207,7 @@
 debugwalk: include, exclude
 grep: print0, all, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude
 heads: rev, active, closed, style, template
-help: 
+help: extension
 identify: rev, num, id, branch, tags
 import: strip, base, force, no-commit, exact, import-branch, message, logfile, date, user, similarity
 incoming: force, newest-first, bundle, rev, patch, git, limit, no-merges, style, template, ssh, remotecmd
diff -r c2e27f7966a7 -r 9e140e05f7c7 tests/test-extension
--- a/tests/test-extension	Wed Jan 20 16:58:48 2010 +0100
+++ b/tests/test-extension	Wed Jan 20 20:24:20 2010 +0200
@@ -153,3 +153,24 @@
 
 echo % show extensions
 hg debugextensions
+
+echo % test limiting help to extension topics
+cat > exthelp.py <<EOF
+"""extension help text"""
+import os
+from mercurial import commands
+
+def exthelp(ui, *args, **kwargs):
+    """command help text"""
+    pass
+
+cmdtable = {
+    "exthelp": (exthelp, [], "hg exthelp"),
+}
+EOF
+exthelppath=`pwd`/exthelp.py
+echo "exthelp=$exthelppath" >> $HGRCPATH
+echo % should show help for exthelp command
+hg help exthelp
+echo % should show help for exthelp extension
+hg help -e exthelp
diff -r c2e27f7966a7 -r 9e140e05f7c7 tests/test-extension.out
--- a/tests/test-extension.out	Wed Jan 20 16:58:48 2010 +0100
+++ b/tests/test-extension.out	Wed Jan 20 20:24:20 2010 +0200
@@ -96,3 +96,18 @@
 % show extensions
 debugissue811
 mq
+% test limiting help to extension topics
+% should show help for exthelp command
+hg exthelp
+
+command help text
+
+use "hg -v help exthelp" to show global options
+% should show help for exthelp extension
+exthelp extension - extension help text
+
+list of commands:
+
+ exthelp   command help text
+
+use "hg -v help exthelp" to show aliases and global options


More information about the Mercurial-devel mailing list