[PATCH 5 of 7] help: format extension lists using RST

Olav Reinert seroton10 at gmail.com
Sat May 26 10:43:50 CDT 2012


# HG changeset patch
# User Olav Reinert <seroton10 at gmail.com>
# Date 1337889858 -7200
# Node ID af24c7cd97df7abb5c9573809db41a9fcc298a8d
# Parent  2fb28096cf46344a620ebd10c892c449b1ce3bc3
help: format extension lists using RST

diff -r 2fb28096cf46 -r af24c7cd97df mercurial/commands.py
--- a/mercurial/commands.py	Thu May 24 21:40:34 2012 +0200
+++ b/mercurial/commands.py	Thu May 24 22:04:18 2012 +0200
@@ -3217,9 +3217,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 = []
@@ -3317,12 +3317,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('')
+        rst.append(_('use "hg help extensions" for information on enabling '
                    'extensions\n'))
+        ui.write(minirst.format('\n'.join(rst), textwidth))
 
     kw = opts.get('keyword')
     if kw:
diff -r 2fb28096cf46 -r af24c7cd97df mercurial/help.py
--- a/mercurial/help.py	Thu May 24 21:40:34 2012 +0200
+++ b/mercurial/help.py	Thu May 24 22:04:18 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' % header)
+        for name, desc in sorted(exts.iteritems()):
+            rst.append('%s:%s: %s' % (' ' * 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()
+    rst.extend(listexts(_('enabled extensions:'), extensions.enabled()))
+    rst.extend(listexts(_('disabled extensions:'), extensions.disabled()))
+    doc = '\n'.join(rst)
     return doc
 
 def optrst(options, verbose):


More information about the Mercurial-devel mailing list