[PATCH 2 of 3] help: format command and option list help using RST

Olav Reinert seroton10 at gmail.com
Sat Jun 2 04:33:58 CDT 2012


# HG changeset patch
# User Olav Reinert <seroton10 at gmail.com>
# Date 1338629140 -7200
# Node ID 98a4e54433dbb02a26405b5e1652efe7276fceba
# Parent  8412a9abf0ab3cc6fc5b770b6514386a7b369c77
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.

diff -r 8412a9abf0ab -r 98a4e54433db mercurial/commands.py
--- 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,30 @@
             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 +3249,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:
diff -r 8412a9abf0ab -r 98a4e54433db tests/test-alias.t
--- a/tests/test-alias.t	Sat Jun 02 11:22:33 2012 +0200
+++ b/tests/test-alias.t	Sat Jun 02 11:25:40 2012 +0200
@@ -340,24 +340,24 @@
   
   basic commands:
   
-   add         add the specified files on the next commit
-   annotate    show changeset information by line for each file
-   clone       make a copy of an existing repository
-   commit      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         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
-   remove      remove the specified files on the next commit
-   serve       start stand-alone webserver
-   status      show changed files in the working directory
-   summary     summarize working directory state
-   update      update working directory (or switch revisions)
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        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           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
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
   
   use "hg help" for the full list of commands or "hg -v" for details
   [255]
@@ -367,24 +367,24 @@
   
   basic commands:
   
-   add         add the specified files on the next commit
-   annotate    show changeset information by line for each file
-   clone       make a copy of an existing repository
-   commit      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         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
-   remove      remove the specified files on the next commit
-   serve       start stand-alone webserver
-   status      show changed files in the working directory
-   summary     summarize working directory state
-   update      update working directory (or switch revisions)
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        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           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
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
   
   use "hg help" for the full list of commands or "hg -v" for details
   [255]
@@ -394,24 +394,24 @@
   
   basic commands:
   
-   add         add the specified files on the next commit
-   annotate    show changeset information by line for each file
-   clone       make a copy of an existing repository
-   commit      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         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
-   remove      remove the specified files on the next commit
-   serve       start stand-alone webserver
-   status      show changed files in the working directory
-   summary     summarize working directory state
-   update      update working directory (or switch revisions)
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        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           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
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
   
   use "hg help" for the full list of commands or "hg -v" for details
   [255]
diff -r 8412a9abf0ab -r 98a4e54433db tests/test-commandserver.py.out
--- a/tests/test-commandserver.py.out	Sat Jun 02 11:22:33 2012 +0200
+++ b/tests/test-commandserver.py.out	Sat Jun 02 11:25:40 2012 +0200
@@ -16,24 +16,24 @@
 
 basic commands:
 
- add         add the specified files on the next commit
- annotate    show changeset information by line for each file
- clone       make a copy of an existing repository
- commit      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         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
- remove      remove the specified files on the next commit
- serve       start stand-alone webserver
- status      show changed files in the working directory
- summary     summarize working directory state
- update      update working directory (or switch revisions)
+ add           add the specified files on the next commit
+ annotate      show changeset information by line for each file
+ clone         make a copy of an existing repository
+ commit        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           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
+ remove        remove the specified files on the next commit
+ serve         start stand-alone webserver
+ status        show changed files in the working directory
+ summary       summarize working directory state
+ update        update working directory (or switch revisions)
 
 use "hg help" for the full list of commands or "hg -v" for details
  runcommand id --quiet
diff -r 8412a9abf0ab -r 98a4e54433db tests/test-extension.t
--- a/tests/test-extension.t	Sat Jun 02 11:22:33 2012 +0200
+++ b/tests/test-extension.t	Sat Jun 02 11:25:40 2012 +0200
@@ -178,8 +178,7 @@
   
   list of commands:
   
-   foo:
-        yet another foo command
+   foo           yet another foo command
   
   global options:
   
@@ -208,10 +207,8 @@
   
   list of commands:
   
-   debugfoobar:
-        yet another debug command
-   foo:
-        yet another foo command
+   debugfoobar   yet another debug command
+   foo           yet another foo command
   
   global options:
   
@@ -328,7 +325,7 @@
   
   list of commands:
   
-   extdiff    use external program to diff repository (or selected files)
+   extdiff       use external program to diff repository (or selected files)
   
   use "hg -v help extdiff" to show builtin aliases and global options
 
diff -r 8412a9abf0ab -r 98a4e54433db tests/test-help.t
--- a/tests/test-help.t	Sat Jun 02 11:22:33 2012 +0200
+++ b/tests/test-help.t	Sat Jun 02 11:25:40 2012 +0200
@@ -5,46 +5,46 @@
   
   basic commands:
   
-   add         add the specified files on the next commit
-   annotate    show changeset information by line for each file
-   clone       make a copy of an existing repository
-   commit      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         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
-   remove      remove the specified files on the next commit
-   serve       start stand-alone webserver
-   status      show changed files in the working directory
-   summary     summarize working directory state
-   update      update working directory (or switch revisions)
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        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           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
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
   
   use "hg help" for the full list of commands or "hg -v" for details
 
   $ hg -q
-   add         add the specified files on the next commit
-   annotate    show changeset information by line for each file
-   clone       make a copy of an existing repository
-   commit      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         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
-   remove      remove the specified files on the next commit
-   serve       start stand-alone webserver
-   status      show changed files in the working directory
-   summary     summarize working directory state
-   update      update working directory (or switch revisions)
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        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           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
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
 
   $ hg help
   Mercurial Distributed SCM
@@ -211,42 +211,26 @@
   
   basic commands:
   
-   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
-   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)
+   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
+   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)
   
   global options:
   
@@ -389,8 +373,8 @@
   $ hg help ad
   list of commands:
   
-   add          add the specified files on the next commit
-   addremove    add all new files, delete all missing files
+   add           add the specified files on the next commit
+   addremove     add all new files, delete all missing files
   
   use "hg -v help ad" to show builtin aliases and global options
 
@@ -539,24 +523,24 @@
   
   basic commands:
   
-   add         add the specified files on the next commit
-   annotate    show changeset information by line for each file
-   clone       make a copy of an existing repository
-   commit      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         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
-   remove      remove the specified files on the next commit
-   serve       start stand-alone webserver
-   status      show changed files in the working directory
-   summary     summarize working directory state
-   update      update working directory (or switch revisions)
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        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           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
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
   
   use "hg help" for the full list of commands or "hg -v" for details
   [255]
@@ -567,24 +551,24 @@
   
   basic commands:
   
-   add         add the specified files on the next commit
-   annotate    show changeset information by line for each file
-   clone       make a copy of an existing repository
-   commit      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         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
-   remove      remove the specified files on the next commit
-   serve       start stand-alone webserver
-   status      show changed files in the working directory
-   summary     summarize working directory state
-   update      update working directory (or switch revisions)
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        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           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
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
   
   use "hg help" for the full list of commands or "hg -v" for details
   [255]
@@ -711,7 +695,7 @@
   
   list of commands:
   
-   nohelp    (no help text available)
+   nohelp        (no help text available)
   
   use "hg -v help helpext" to show builtin aliases and global options
 
diff -r 8412a9abf0ab -r 98a4e54433db tests/test-strict.t
--- a/tests/test-strict.t	Sat Jun 02 11:22:33 2012 +0200
+++ b/tests/test-strict.t	Sat Jun 02 11:25:40 2012 +0200
@@ -19,24 +19,24 @@
   
   basic commands:
   
-   add         add the specified files on the next commit
-   annotate    show changeset information by line for each file
-   clone       make a copy of an existing repository
-   commit      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         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
-   remove      remove the specified files on the next commit
-   serve       start stand-alone webserver
-   status      show changed files in the working directory
-   summary     summarize working directory state
-   update      update working directory (or switch revisions)
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        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           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
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
   
   use "hg help" for the full list of commands or "hg -v" for details
   [255]


More information about the Mercurial-devel mailing list