help: format extension lists using RST
authorOlav Reinert <seroton10@gmail.com>
Sat, 02 Jun 2012 11:22:33 +0200
changeset 16852 af69b2b64d6e
parent 16851 c739227b5eea
child 16853 7863ff383894
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.
mercurial/commands.py
mercurial/help.py
--- a/mercurial/commands.py	Sun Jun 03 09:06:15 2012 +0200
+++ 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:
--- a/mercurial/help.py	Sun Jun 03 09:06:15 2012 +0200
+++ 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):