Patchwork [1,of,2,V2] show: fix formatting of multiple commands

login
register
mail settings
Submitter Gregory Szorc
Date April 13, 2017, 3:31 a.m.
Message ID <60177a9b778cb65fdefd.1492054295@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/20155/
State Accepted
Headers show

Comments

Gregory Szorc - April 13, 2017, 3:31 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1492054124 25200
#      Wed Apr 12 20:28:44 2017 -0700
# Node ID 60177a9b778cb65fdefd4486ce51475a746c4cb6
# Parent  6ce09d2cc2db6aeed0b46da1b26426798d91833c
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.
Yuya Nishihara - April 13, 2017, 12:25 p.m.
On Wed, 12 Apr 2017 20:31:35 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1492054124 25200
> #      Wed Apr 12 20:28:44 2017 -0700
> # Node ID 60177a9b778cb65fdefd4486ce51475a746c4cb6
> # Parent  6ce09d2cc2db6aeed0b46da1b26426798d91833c
> show: fix formatting of multiple commands

Queued these, thanks.

> +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)))

Perhaps you want a field definition list: ':%s: %s'.

Patch

diff --git a/hgext/show.py b/hgext/show.py
--- a/hgext/show.py
+++ b/hgext/show.py
@@ -71,7 +71,6 @@  def show(ui, repo, view=None, template=N
        ``-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 @@  def showbookmarks(ui, repo, fm):
 # 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()
diff --git a/tests/test-show.t b/tests/test-show.t
--- a/tests/test-show.t
+++ b/tests/test-show.t
@@ -37,7 +37,7 @@  No arguments shows available views
   
       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)