commands: wrap short descriptions in 'hg help'
authorMartin Geisler <mg@lazybytes.net>
Wed, 24 Jun 2009 19:15:58 +0200
changeset 8938 9b8c9266c59d
parent 8937 ea798e03a32e
child 8939 bc9ac7a29a73
commands: wrap short descriptions in 'hg help' The code for wrapping a single line of text with a hanging indent was duplicated in commands and help -- it's now moved to a new function called wrap in util. The function defaults to a line width is 78 chars, and this un-wraps some command line flag descriptions, hence the test output changes.
mercurial/commands.py
mercurial/help.py
mercurial/util.py
tests/test-extension.out
tests/test-record.out
--- a/mercurial/commands.py	Wed Jun 24 18:40:13 2009 +0200
+++ b/mercurial/commands.py	Wed Jun 24 19:15:58 2009 +0200
@@ -8,7 +8,7 @@
 from node import hex, nullid, nullrev, short
 from lock import release
 from i18n import _, gettext
-import os, re, sys, textwrap, subprocess, difflib, time
+import os, re, sys, subprocess, difflib, time
 import hg, util, revlog, bundlerepo, extensions, copies, context, error
 import patch, help, mdiff, tempfile, url, encoding
 import archival, changegroup, cmdutil, sshserver, hbisect
@@ -1514,7 +1514,7 @@
                 commands = cmds[f].replace("|",", ")
                 ui.write(" %s:\n      %s\n"%(commands, h[f]))
             else:
-                ui.write(' %-*s   %s\n' % (m, f, h[f]))
+                ui.write(' %-*s   %s\n' % (m, f, util.wrap(h[f], m + 4)))
 
         if name != 'shortlist':
             exts, maxlength = extensions.enabled()
@@ -1617,11 +1617,8 @@
         opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
         for first, second in opt_output:
             if second:
-                # wrap descriptions at 70 characters, just like the
-                # main help texts
-                second = textwrap.wrap(second, width=70 - opts_len - 3)
-                pad = '\n' + ' ' * (opts_len + 3)
-                ui.write(" %-*s  %s\n" % (opts_len, first, pad.join(second)))
+                second = util.wrap(second, opts_len + 3)
+                ui.write(" %-*s  %s\n" % (opts_len, first, second))
             else:
                 ui.write("%s\n" % first)
 
--- a/mercurial/help.py	Wed Jun 24 18:40:13 2009 +0200
+++ b/mercurial/help.py	Wed Jun 24 19:15:58 2009 +0200
@@ -5,9 +5,8 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2, incorporated herein by reference.
 
-import textwrap
 from i18n import _
-import extensions
+import extensions, util
 
 
 def moduledoc(file):
@@ -46,11 +45,8 @@
         return ''
     result = '\n%s\n\n' % header
     for name, desc in sorted(exts.iteritems()):
-        # wrap desc at 70 characters, just like the main help texts
-        desc = textwrap.wrap(desc, width=78 - maxlength - 4)
-        pad = '\n' + ' ' * (maxlength + 4)
-        result += ' %s   %s\n' % (name.ljust(maxlength),
-                                  pad.join(desc))
+        desc = util.wrap(desc, maxlength + 4)
+        result += ' %s   %s\n' % (name.ljust(maxlength), desc)
     return result
 
 def extshelp():
--- a/mercurial/util.py	Wed Jun 24 18:40:13 2009 +0200
+++ b/mercurial/util.py	Wed Jun 24 19:15:58 2009 +0200
@@ -16,7 +16,7 @@
 from i18n import _
 import error, osutil
 import cStringIO, errno, re, shutil, sys, tempfile, traceback
-import os, stat, time, calendar, random
+import os, stat, time, calendar, random, textwrap
 import imp
 
 # Python compatibility
@@ -1242,6 +1242,10 @@
         pass
     return 80
 
+def wrap(line, hangindent, width=78):
+    padding = '\n' + ' ' * hangindent
+    return padding.join(textwrap.wrap(line, width=width - hangindent))
+
 def iterlines(iterator):
     for chunk in iterator:
         for line in chunk.splitlines():
--- a/tests/test-extension.out	Wed Jun 24 18:40:13 2009 +0200
+++ b/tests/test-extension.out	Wed Jun 24 19:15:58 2009 +0200
@@ -36,8 +36,7 @@
 global options:
  -R --repository      repository root directory or symbolic path name
     --cwd             change working directory
- -y --noninteractive  do not prompt, assume 'yes' for any required
-                      answers
+ -y --noninteractive  do not prompt, assume 'yes' for any required answers
  -q --quiet           suppress output
  -v --verbose         enable additional output
     --config          set/override config option
--- a/tests/test-record.out	Wed Jun 24 18:40:13 2009 +0200
+++ b/tests/test-record.out	Wed Jun 24 19:15:58 2009 +0200
@@ -27,10 +27,8 @@
 
 options:
 
- -A --addremove     mark new/missing files as added/removed before
-                    committing
-    --close-branch  mark a branch as closed, hiding it from the branch
-                    list
+ -A --addremove     mark new/missing files as added/removed before committing
+    --close-branch  mark a branch as closed, hiding it from the branch list
  -I --include       include names matching the given patterns
  -X --exclude       exclude names matching the given patterns
  -m --message       use <text> as commit message