[PATCH 02 of 10] help: use rst for version text

Erik Zielke ez at aragost.com
Wed Nov 17 11:11:01 CST 2010


# HG changeset patch
# User Erik Zielke <ez at aragost.com>
# Date 1289291331 -3600
# Node ID 8b1c0f96014d2a6c955a9a92c5efd72358b48e08
# Parent  f81b256b8a7e02a7daae1868528120a7f1e322c1
help: use rst for version text

Generate rst for version text and format that, instead of directly
printing the version string.

diff -r f81b256b8a7e -r 8b1c0f96014d mercurial/commands.py
--- a/mercurial/commands.py	Tue Nov 09 09:19:03 2010 +0100
+++ b/mercurial/commands.py	Tue Nov 09 09:28:51 2010 +0100
@@ -1891,8 +1891,10 @@
 
     def helpcmd(name):
         if with_version:
-            version_(ui)
-            ui.write('\n')
+            versionrst = help.generateversionrst(ui.quiet)
+            formatted = minirst.format(versionrst, textwidth)
+            ui.write(formatted)
+            ui.write('\n\n')
 
         try:
             aliases, entry = cmdutil.findcmd(name, table, strict=unknowncmd)
@@ -2069,7 +2071,10 @@
     else:
         # program name
         if ui.verbose or with_version:
-            version_(ui)
+            versionrst = help.generateversionrst(ui.quiet)
+            formatted = minirst.format(versionrst, textwidth)
+            ui.write(formatted)
+            ui.write('\n')
         else:
             ui.status(_("Mercurial Distributed SCM\n"))
         ui.status('\n')
@@ -3893,15 +3898,9 @@
 
 def version_(ui):
     """output version and copyright information"""
-    ui.write(_("Mercurial Distributed SCM (version %s)\n")
-             % util.version())
-    ui.status(_(
-        "(see http://mercurial.selenic.com for more information)\n"
-        "\nCopyright (C) 2005-2010 Matt Mackall and others\n"
-        "This is free software; see the source for copying conditions. "
-        "There is NO\nwarranty; "
-        "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
-    ))
+    textwidth = ui.termwidth() - 2
+    versionrst = help.generateversionrst(ui.quiet)
+    ui.write(minirst.format(versionrst, textwidth))
 
 # Command options and aliases are listed here, alphabetically
 
diff -r f81b256b8a7e -r 8b1c0f96014d mercurial/help.py
--- a/mercurial/help.py	Tue Nov 09 09:19:03 2010 +0100
+++ b/mercurial/help.py	Tue Nov 09 09:28:51 2010 +0100
@@ -7,7 +7,7 @@
 
 from i18n import gettext, _
 import sys, os, textwrap
-import extensions
+import extensions, util
 
 
 def moduledoc(file):
@@ -165,6 +165,27 @@
     if d['aliases']:
         ui.write(_("    aliases: %s\n\n") % " ".join(d['aliases']))
 
+def generateversionrst(quiet):
+    versionlines = []
+    versionlines.append(_("| Mercurial Distributed SCM (version %s)\n")
+             % util.version())
+
+    if not quiet:
+        versiontext = _(
+"""
+| (see http://mercurial.selenic.com for more information)
+
+..
+
+| Copyright (C) 2005-2010 Matt Mackall and others
+| This is free software; see the source for copying conditions. There is NO
+  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+"""
+        )
+
+        versionlines.append(versiontext)
+
+    return ''.join(versionlines)
 
 helptable = [
     (["config", "hgrc"], _("Configuration Files"), loaddoc('config')),


More information about the Mercurial-devel mailing list