[PATCH 1 of 3] help: format extension lists using RST

Olav Reinert seroton10 at gmail.com
Sat Jun 2 04:33:57 CDT 2012


# HG changeset patch
# User Olav Reinert <seroton10 at gmail.com>
# Date 1338628953 -7200
# Node ID 8412a9abf0ab3cc6fc5b770b6514386a7b369c77
# Parent  357e6bcfb61973478bfbe4cf5652026a6bda7ef7
help: format extension lists using RST

This change is a move towards generating all help text as a list of strings
marked up with RST.

diff -r 357e6bcfb619 -r 8412a9abf0ab mercurial/commands.py
--- a/mercurial/commands.py	Fri Jun 01 23:44:10 2012 -0500
+++ b/mercurial/commands.py	Sat Jun 02 11:22:33 2012 +0200
@@ -3218,9 +3218,9 @@
                                              hangindent=' ' * (m + 4))))
 
         if not name:
-            text = help.listexts(_('enabled extensions:'), extensions.enabled())
-            if text:
-                ui.write("\n%s" % minirst.format(text, textwidth))
+            rst = help.listexts(_('enabled extensions:'), extensions.enabled())
+            if rst:
+                ui.write("\n%s" % minirst.format('\n'.join(rst), textwidth))
 
             ui.write(_("\nadditional help topics:\n\n"))
             topics = []
@@ -3318,12 +3318,12 @@
                                                ui.configbool('ui', 'strict'))
         doc = gettext(mod.__doc__).splitlines()[0]
 
-        msg = help.listexts(_("'%s' is provided by the following "
+        rst = help.listexts(_("'%s' is provided by the following "
                               "extension:") % cmd, {ext: doc}, indent=4)
-        ui.write(minirst.format(msg, textwidth))
-        ui.write('\n')
-        ui.write(_('use "hg help extensions" for information on enabling '
+        rst.append('\n')
+        rst.append(_('use "hg help extensions" for information on enabling '
                    'extensions\n'))
+        ui.write(minirst.format(''.join(rst), textwidth))
 
     kw = opts.get('keyword')
     if kw:
diff -r 357e6bcfb619 -r 8412a9abf0ab mercurial/help.py
--- a/mercurial/help.py	Fri Jun 01 23:44:10 2012 -0500
+++ b/mercurial/help.py	Sat Jun 02 11:22:33 2012 +0200
@@ -12,19 +12,18 @@
 
 def listexts(header, exts, indent=1):
     '''return a text listing of the given extensions'''
-    if not exts:
-        return ''
-    maxlength = max(len(e) for e in exts)
-    result = '\n%s\n\n' % header
-    for name, desc in sorted(exts.iteritems()):
-        result += '%s%-*s %s\n' % (' ' * indent, maxlength + 2,
-                                   ':%s:' % name, desc)
-    return result
+    rst = []
+    if exts:
+        rst.append('\n%s\n\n' % header)
+        for name, desc in sorted(exts.iteritems()):
+            rst.append('%s:%s: %s\n' % (' ' * indent, name, desc))
+    return rst
 
 def extshelp():
-    doc = loaddoc('extensions')()
-    doc += listexts(_('enabled extensions:'), extensions.enabled())
-    doc += listexts(_('disabled extensions:'), extensions.disabled())
+    rst = loaddoc('extensions')().splitlines(True)
+    rst.extend(listexts(_('enabled extensions:'), extensions.enabled()))
+    rst.extend(listexts(_('disabled extensions:'), extensions.disabled()))
+    doc = ''.join(rst)
     return doc
 
 def optrst(options, verbose):


More information about the Mercurial-devel mailing list