diff mercurial/commands.py @ 8039:18081ce1e630

commands: automatically word-wrap cmdline options Some of the descriptions of command line options were getting quite long, and when translated they are likely to grow even longer. This word-wraps them at 70 characters, just like the help texts. We could have opted to wrap them at the terminal width instead, but I think it looks better to have them be consistent with the help texts.
author Martin Geisler <mg@lazybytes.net>
date Thu, 09 Apr 2009 14:43:02 +0200
parents 2ee6769afe82
children 545fb915fe16
line wrap: on
line diff
--- a/mercurial/commands.py	Thu Apr 09 10:48:07 2009 +0200
+++ b/mercurial/commands.py	Thu Apr 09 14:43:02 2009 +0200
@@ -7,7 +7,7 @@
 
 from node import hex, nullid, nullrev, short
 from i18n import _, gettext
-import os, re, sys
+import os, re, sys, textwrap
 import hg, util, revlog, bundlerepo, extensions, copies, context, error
 import difflib, patch, time, help, mdiff, tempfile, url, encoding
 import archival, changegroup, cmdutil, hgweb.server, sshserver, hbisect
@@ -1532,7 +1532,11 @@
         opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0])
         for first, second in opt_output:
             if second:
-                ui.write(" %-*s  %s\n" % (opts_len, first, 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)))
             else:
                 ui.write("%s\n" % first)