[PATCH 07 of 10] help: generate and use rst for extension help

Erik Zielke ez at aragost.com
Wed Nov 17 11:11:06 CST 2010


# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1290013165 -3600
# Node ID a6aca1a96f79cfae79eff0bca75461ee8ec10483
# Parent  7162beaa1465404a34593d1b647881229f7e947f
help: generate and use rst for extension help

diff -r 7162beaa1465 -r a6aca1a96f79 mercurial/commands.py
--- a/mercurial/commands.py	Tue Nov 09 11:15:20 2010 +0100
+++ b/mercurial/commands.py	Wed Nov 17 17:59:25 2010 +0100
@@ -1964,34 +1964,11 @@
         ui.write('\n')
 
     def helpext(name):
-        try:
-            mod = extensions.find(name)
-            doc = gettext(mod.__doc__) or _('no help text available')
-        except KeyError:
-            mod = None
-            doc = extensions.disabledext(name)
-            if not doc:
-                raise error.UnknownCommand(name)
-
-        if '\n' not in doc:
-            head, tail = doc, ""
-        else:
-            head, tail = doc.split('\n', 1)
-        ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head))
-        if tail:
-            ui.write(minirst.format(tail, textwidth))
-            ui.status('\n\n')
-
-        if mod:
-            try:
-                ct = mod.cmdtable
-            except AttributeError:
-                ct = {}
-            modcmds = set([c.split('|', 1)[0] for c in ct])
-            helplist(_('list of commands:\n\n'), False, modcmds.__contains__)
-        else:
-            ui.write(_('use "hg help extensions" for information on enabling '
-                       'extensions\n'))
+        helpextrst = help.generatethelpextrst(helpconfig)
+        formatted, pruned = minirst.format(helpextrst, textwidth,
+                                   keep=helpconfig['keep'])
+        ui.write(formatted)
+        ui.write('\n')
 
     def helpextcmd(name):
         cmd, ext, mod = extensions.disabledcmd(name, ui.config('ui', 'strict'))
diff -r 7162beaa1465 -r a6aca1a96f79 mercurial/help.py
--- a/mercurial/help.py	Tue Nov 09 11:15:20 2010 +0100
+++ b/mercurial/help.py	Wed Nov 17 17:59:25 2010 +0100
@@ -336,8 +336,6 @@
                 if list_max > maxlen:
                     maxlen = list_max
 
-
-
         for name, list in optionlists:
             if len(list) > 0:
                 if not quiet:
@@ -407,6 +405,48 @@
 
     return ''.join(lines)
 
+def generatethelpextrst(helpconfig):
+    """Returns rst help for the extension with the given name"""
+
+    try:
+        mod = extensions.find(helpconfig['name'])
+        doc = gettext(mod.__doc__) or _('no help text available')
+    except KeyError:
+        mod = None
+        doc = extensions.disabledext(helpconfig['name'])
+        if not doc:
+            raise error.UnknownCommand(helpconfig['name'])
+
+    if '\n' not in doc:
+        head, tail = doc, ""
+    else:
+        head, tail = doc.split('\n', 1)
+
+    lines = []
+    lines.append(_('%s extension - %s\n\n') %
+                 (helpconfig['name'].split('.')[-1], head))
+    if tail:
+        lines.append(tail)
+
+    if mod:
+        try:
+           ct = mod.cmdtable
+        except AttributeError:
+            ct = {}
+        modcmds = set([c.split('|', 1)[0] for c in ct])
+        helpconfig['commandtable'] = ct
+        lines.append('\n\n')
+        helplistrst = generatehelplistrst(_('list of commands:\n\n'),
+                                          helpconfig,
+                                          select=modcmds.__contains__)
+
+        lines.append(helplistrst)
+    else:
+        lines.append(_('use "hg help extensions" for information on enabling '
+                   'extensions\n'))
+    return ''.join(lines)
+
+
 helptable = [
     (["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
     (["dates"], _("Date Formats"), loaddoc('dates')),


More information about the Mercurial-devel mailing list