changeset 31943:3e9f118cc834

show: fix formatting of multiple commands Because we're formatting to RST, short lines wrap and there needs to be an extra line break between paragraphs to prevent that. In addition, the indentation in the old code was a bit off. Refactor the code to a function (so we don't leak variables outside the module) and modify it so it renders more correctly.
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 12 Apr 2017 20:28:44 -0700
parents bc0579a25f82
children 99bc93147d87
files hgext/show.py tests/test-show.t
diffstat 2 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/show.py	Wed Apr 12 18:42:20 2017 -0700
+++ b/hgext/show.py	Wed Apr 12 20:28:44 2017 -0700
@@ -71,7 +71,6 @@
        ``-T/--template``.
 
     List of available views:
-
     """
     if ui.plain() and not template:
         hint = _('invoke with -T/--template to control output format')
@@ -134,7 +133,15 @@
 # into core or when another extension wants to provide a view, we'll need
 # to do this more robustly.
 # TODO make this more robust.
-longest = max(map(len, showview._table.keys()))
-for key in sorted(showview._table.keys()):
-    cmdtable['show'][0].__doc__ += pycompat.sysstr(' %s   %s\n' % (
-        key.ljust(longest), showview._table[key]._origdoc))
+def _updatedocstring():
+    longest = max(map(len, showview._table.keys()))
+    entries = []
+    for key in sorted(showview._table.keys()):
+        entries.append(pycompat.sysstr('    %s   %s' % (
+            key.ljust(longest), showview._table[key]._origdoc)))
+
+    cmdtable['show'][0].__doc__ = pycompat.sysstr('%s\n\n%s\n    ') % (
+        cmdtable['show'][0].__doc__.rstrip(),
+        pycompat.sysstr('\n\n').join(entries))
+
+_updatedocstring()
--- a/tests/test-show.t	Wed Apr 12 18:42:20 2017 -0700
+++ b/tests/test-show.t	Wed Apr 12 20:28:44 2017 -0700
@@ -37,7 +37,7 @@
   
       List of available views:
   
-       bookmarks   bookmarks and their associated changeset
+      bookmarks   bookmarks and their associated changeset
   
   (use 'hg help -e show' to show help for the show extension)