diff mercurial/commands.py @ 16853:7863ff383894

help: format command and option list help using RST This patch changes the function which generates help text about commands and options to use RST formatting. Tables describing options have been formatted using RST table markup for some time already, so their appearance does not change. Command lists, however, change appearance. To format non-verbose command lists, RST field list markup was chosen, because it resembles the old format: <http://docutils.sourceforge.net/docs/user/rst/quickref.html#field-lists> In the old (hand-coded) format of non-verbose command lists, the left column is 12 characters wide. Our minirst implementation formats field lists with a left column 14 characters wide, so this patch changes the appearance of help output correspondingly: <http://markmail.org/message/krl4cxopsnii7s6z?q=mercurial+reinert+from:%22Olav+Reinert%22&page=2> The minirst markup most closely resembling the old verbose command lists is definition lists. But using it would cause a blank line to be inserted between each command definition, making the output excessively long, and no more useful than before. To avoid this, I chose to use field lists also for verbose command help, resulting in output like this example: add add the specified files on the next commit annotate, blame show changeset information by line for each file clone make a copy of an existing repository commit, ci commit the specified files or all outstanding changes diff diff repository (or selected files) export dump the header and diffs for one or more changesets forget forget the specified files on the next commit init create a new repository in the given directory log, history show revision history of entire repository or files merge merge working directory with another revision phase set or show the current phase name pull pull changes from the specified source push push changes to the specified destination qdiff diff of the current patch and subsequent modifications qinit init a new queue repository (DEPRECATED) qnew create a new patch qpop pop the current patch off the stack qpush push the next patch onto the stack qrefresh update the current patch remove, rm remove the specified files on the next commit serve start stand-alone webserver status, st show changed files in the working directory summary, sum summarize working directory state update, up, checkout, co update working directory (or switch revisions) This change is a move towards generating all help text as a list of strings marked up with RST.
author Olav Reinert <seroton10@gmail.com>
date Sat, 02 Jun 2012 11:25:40 +0200
parents af69b2b64d6e
children d71ada5a6a33
line wrap: on
line diff
--- a/mercurial/commands.py	Sat Jun 02 11:22:33 2012 +0200
+++ b/mercurial/commands.py	Sat Jun 02 11:25:40 2012 +0200
@@ -3205,30 +3205,29 @@
             ui.status(_('no commands defined\n'))
             return
 
-        ui.status(header)
+        rst = []
+        if not ui.quiet:
+            rst.append(header)
         fns = sorted(h)
-        m = max(map(len, fns))
         for f in fns:
             if ui.verbose:
                 commands = cmds[f].replace("|",", ")
-                ui.write(" %s:\n      %s\n"%(commands, h[f]))
+                rst.append(" :%s: %s\n" % (commands, h[f]))
             else:
-                ui.write('%s\n' % (util.wrap(h[f], textwidth,
-                                             initindent=' %-*s    ' % (m, f),
-                                             hangindent=' ' * (m + 4))))
+                rst.append(' :%s: %s\n' % (f, h[f]))
 
         if not name:
-            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"))
+            exts = help.listexts(_('enabled extensions:'), extensions.enabled())
+            if exts:
+                rst.append('\n')
+                rst.extend(exts)
+
+            rst.append(_("\nadditional help topics:\n\n"))
             topics = []
             for names, header, doc in help.helptable:
                 topics.append((sorted(names, key=len, reverse=True)[0], header))
-            topics_len = max([len(s[0]) for s in topics])
             for t, desc in topics:
-                ui.write(" %-*s   %s\n" % (topics_len, t, desc))
+                rst.append(" :%s: %s\n" % (t, desc))
 
         optlist = []
         if not ui.quiet:
@@ -3249,17 +3248,12 @@
                             'global options') % (name and " " + name or "")
                 optlist.append((msg, ()))
 
-        if not optlist:
-            return
-
-        rst = ''
-        for title, options in optlist:
-            rst += '\n%s\n' % title
-            if options:
-                rst += "\n"
-                rst += help.optrst(options, ui.verbose)
-                rst += '\n'
-        ui.write('\n' + minirst.format(rst, textwidth))
+        if optlist:
+            for title, options in optlist:
+                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))
 
     def helptopic(name):
         for names, header, doc in help.helptable: