changeset 16854:d71ada5a6a33

help: format all output using RST This change is the last patch needed to implement help text generation based only on formatting a single text object marked up with RST.
author Olav Reinert <seroton10@gmail.com>
date Sat, 02 Jun 2012 11:28:43 +0200
parents 7863ff383894
children 57a5ac98f9b7
files mercurial/commands.py tests/test-qrecord.t
diffstat 2 files changed, 38 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sat Jun 02 11:25:40 2012 +0200
+++ b/mercurial/commands.py	Sat Jun 02 11:28:43 2012 +0200
@@ -3097,16 +3097,18 @@
             # except block, nor can be used inside a lambda. python issue4617
             prefix = inst.args[0]
             select = lambda c: c.lstrip('^').startswith(prefix)
-            helplist(select)
-            return
+            rst = helplist(select)
+            return rst
+
+        rst = []
 
         # check if it's an invalid alias and display its error if it is
         if getattr(entry[0], 'badalias', False):
             if not unknowncmd:
+                ui.pushbuffer()
                 entry[0](ui)
-            return
-
-        rst = []
+                rst.append(ui.popbuffer())
+            return rst
 
         # synopsis
         if len(entry) > 2:
@@ -3165,10 +3167,7 @@
             elif not ui.quiet:
                 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)
+        return rst
 
 
     def helplist(select=None):
@@ -3201,11 +3200,12 @@
             h[f] = doc.splitlines()[0].rstrip()
             cmds[f] = c.lstrip("^")
 
+        rst = []
         if not h:
-            ui.status(_('no commands defined\n'))
-            return
-
-        rst = []
+            if not ui.quiet:
+                rst.append(_('no commands defined\n'))
+            return rst
+
         if not ui.quiet:
             rst.append(header)
         fns = sorted(h)
@@ -3253,7 +3253,7 @@
                 rst.append('\n%s\n' % title)
                 if options:
                     rst.append('\n%s\n' % help.optrst(options, ui.verbose))
-        ui.write(minirst.format(''.join(rst), textwidth))
+        return rst
 
     def helptopic(name):
         for names, header, doc in help.helptable:
@@ -3275,7 +3275,7 @@
                        'the %s command\n') % (name, name))
         except error.UnknownCommand:
             pass
-        ui.write(minirst.format(''.join(rst), textwidth))
+        return rst
 
     def helpext(name):
         try:
@@ -3291,10 +3291,10 @@
             head, tail = doc, ""
         else:
             head, tail = doc.split('\n', 1)
-        ui.write(_('%s extension - %s\n\n') % (name.split('.')[-1], head))
+        rst = [_('%s extension - %s\n\n') % (name.split('.')[-1], head)]
         if tail:
-            ui.write(minirst.format(tail, textwidth))
-            ui.status('\n')
+            rst.extend(tail.splitlines(True))
+            rst.append('\n')
 
         if mod:
             try:
@@ -3302,10 +3302,11 @@
             except AttributeError:
                 ct = {}
             modcmds = set([c.split('|', 1)[0] for c in ct])
-            helplist(modcmds.__contains__)
+            rst.extend(helplist(modcmds.__contains__))
         else:
-            ui.write(_('use "hg help extensions" for information on enabling '
+            rst.append(_('use "hg help extensions" for information on enabling '
                        'extensions\n'))
+        return rst
 
     def helpextcmd(name):
         cmd, ext, mod = extensions.disabledcmd(ui, name,
@@ -3317,8 +3318,10 @@
         rst.append('\n')
         rst.append(_('use "hg help extensions" for information on enabling '
                    'extensions\n'))
-        ui.write(minirst.format(''.join(rst), textwidth))
-
+        return rst
+
+
+    rst = []
     kw = opts.get('keyword')
     if kw:
         matches = help.topicmatch(kw)
@@ -3327,12 +3330,9 @@
                          ('extensions', _('Extensions')),
                          ('extensioncommands', _('Extension Commands'))):
             if matches[t]:
-                ui.write('%s:\n\n' % title)
-                rst = ''.join(minirst.maketable(matches[t], 1))
-                ui.write(minirst.format(rst))
-        return
-
-    if name and name != 'shortlist':
+                rst.append('%s:\n\n' % title)
+                rst.extend(minirst.maketable(matches[t], 1))
+    elif name and name != 'shortlist':
         i = None
         if unknowncmd:
             queries = (helpextcmd,)
@@ -3344,7 +3344,7 @@
             queries = (helptopic, helpcmd, helpext, helpextcmd)
         for f in queries:
             try:
-                f(name)
+                rst = f(name)
                 i = None
                 break
             except error.UnknownCommand, inst:
@@ -3353,9 +3353,13 @@
             raise i
     else:
         # program name
-        ui.status(_("Mercurial Distributed SCM\n"))
-        ui.status('\n')
-        helplist()
+        if not ui.quiet:
+            rst = [_("Mercurial Distributed SCM\n"), '\n']
+        rst.extend(helplist())
+
+    keep = ui.verbose and ['verbose'] or []
+    formatted, pruned = minirst.format(''.join(rst), textwidth, keep=keep)
+    ui.write(formatted)
 
 
 @command('identify|id',
--- a/tests/test-qrecord.t	Sat Jun 02 11:25:40 2012 +0200
+++ b/tests/test-qrecord.t	Sat Jun 02 11:28:43 2012 +0200
@@ -6,7 +6,8 @@
 help record (no record)
 
   $ hg help record
-  record extension - commands to interactively select changes for commit/qrefresh
+  record extension - commands to interactively select changes for
+  commit/qrefresh
   
   use "hg help extensions" for information on enabling extensions