[PATCH 4 of 4] help: format command help using RST

Olav Reinert seroton10 at gmail.com
Fri Jun 1 06:41:48 CDT 2012


# HG changeset patch
# User Olav Reinert <seroton10 at gmail.com>
# Date 1338546930 -7200
# Node ID d90e71faa62a044aac8d2c53e95044650bb06577
# Parent  1af1e72fd4927a7a872c6a4ebf1106d542828b07
help: format command help using RST

diff -r 1af1e72fd492 -r d90e71faa62a mercurial/commands.py
--- a/mercurial/commands.py	Fri Jun 01 12:15:45 2012 +0200
+++ b/mercurial/commands.py	Fri Jun 01 12:35:30 2012 +0200
@@ -3106,20 +3106,20 @@
                 entry[0](ui)
             return
 
-        rst = ""
+        rst = []
 
         # synopsis
         if len(entry) > 2:
             if entry[2].startswith('hg'):
-                rst += "%s\n" % entry[2]
+                rst.append("%s\n" % entry[2])
             else:
-                rst += 'hg %s %s\n' % (aliases[0], entry[2])
+                rst.append('hg %s %s\n' % (aliases[0], entry[2]))
         else:
-            rst += 'hg %s\n' % aliases[0]
-
+            rst.append('hg %s\n' % aliases[0])
         # aliases
         if full and not ui.quiet and len(aliases) > 1:
-            rst += _("\naliases: %s\n") % ', '.join(aliases[1:])
+            rst.append(_("\naliases: %s\n") % ', '.join(aliases[1:]))
+        rst.append('\n')
 
         # description
         doc = gettext(entry[0].__doc__)
@@ -3130,9 +3130,12 @@
                 doc = _('shell alias for::\n\n    %s') % entry[0].definition[1:]
             else:
                 doc = _('alias for: hg %s\n\n%s') % (entry[0].definition, doc)
+        doc = doc.splitlines(True)
         if ui.quiet or not full:
-            doc = doc.splitlines()[0]
-        rst += "\n" + doc + "\n"
+            rst.append(doc[0])
+        else:
+            rst.extend(doc)
+        rst.append('\n')
 
         # check if this command shadows a non-trivial (multi-line)
         # extension help text
@@ -3142,33 +3145,30 @@
             if '\n' in doc.strip():
                 msg = _('use "hg help -e %s" to show help for '
                         'the %s extension') % (name, name)
-                rst += '\n%s\n' % msg
+                rst.append('\n%s\n' % msg)
         except KeyError:
             pass
 
         # options
         if not ui.quiet and entry[1]:
-            rst += '\n'
-            rst += _("options:")
-            rst += '\n\n'
-            rst += help.optrst(entry[1], ui.verbose)
+            rst.append('\n%s\n\n' % _("options:"))
+            rst.append(help.optrst(entry[1], ui.verbose))
 
         if ui.verbose:
-            rst += '\n'
-            rst += _("global options:")
-            rst += '\n\n'
-            rst += help.optrst(globalopts, ui.verbose)
-
-        keep = ui.verbose and ['verbose'] or []
-        formatted, pruned = minirst.format(rst, textwidth, keep=keep)
-        ui.write(formatted)
+            rst.append('\n%s\n\n' % _("global options:"))
+            rst.append(help.optrst(globalopts, ui.verbose))
 
         if not ui.verbose:
             if not full:
-                ui.write(_('\nuse "hg help %s" to show the full help text\n')
+                rst.append(_('\nuse "hg help %s" to show the full help text\n')
                            % name)
             elif not ui.quiet:
-                ui.write(_('\nuse "hg -v help %s" to show more info\n') % name)
+                rst.append(_('\nuse "hg -v help %s" to show more info\n')
+                           % name)
+
+        keep = ui.verbose and ['verbose'] or []
+        formatted, pruned = minirst.format(''.join(rst), textwidth, keep=keep)
+        ui.write(formatted)
 
 
     def helplist(select=None):


More information about the Mercurial-devel mailing list