[PATCH 2 of 4] commands: add template support for version

Mathias De Maré mathias.demare at gmail.com
Mon Aug 8 11:54:44 EDT 2016


# HG changeset patch
# User Mathias De Maré <mathias.demare at gmail.com>
# Date 1470113194 -7200
#      Tue Aug 02 06:46:34 2016 +0200
# Node ID 2a711c2a71c1e5e562fc988cfe9011ebf3d8e6e9
# Parent  4fb94670f2a3eb0247a040f0506a2f6580e3dca9
commands: add template support for version

Example output (lines shortened manually):
hg version -Tjson -v
[
 {
  "enabledextensions": {"purge" : {"version" : "", "place" : "internal"} },
  "fullversion": "Mercurial Distributed SCM (version 3.9-rc+26-f491b3)\n",
  "license": "(see https://mercurial-scm.org for...",
  "version": "3.9-rc+26-f491b303946d"
 }
]

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -7242,12 +7242,15 @@
     """
     return hg.verify(repo)
 
- at command('version', [], norepo=True)
-def version_(ui):
+ at command('version', [] + formatteropts, norepo=True)
+def version_(ui, **opts):
     """output version and copyright information"""
-    ui.write(_("Mercurial Distributed SCM (version %s)\n")
-             % util.version())
-    ui.status(_(
+    fm = ui.formatter('version', opts)
+    fm.startitem()
+    fullversion = _("Mercurial Distributed SCM (version %s)\n") % util.version()
+    fm.write('fullversion', '%s', fullversion)
+    fm.data(version=util.version())
+    fm.condwrite(not ui.quiet, 'license', '%s', _(
         "(see https://mercurial-scm.org for more information)\n"
         "\nCopyright (C) 2005-2016 Matt Mackall and others\n"
         "This is free software; see the source for copying conditions. "
@@ -7255,8 +7258,9 @@
         "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
     ))
 
-    ui.note(_("\nEnabled extensions:\n\n"))
     if ui.verbose:
+        fm.plain(_("\nEnabled extensions:\n\n"))
+        enabledextensions = {}
         # format names and versions into columns
         names = []
         vers = []
@@ -7271,8 +7275,14 @@
         if names:
             maxnamelen = max(len(n) for n in names)
             for i, name in enumerate(names):
-                ui.write("  %-*s  %s  %s\n" %
+                fm.plain("  %-*s  %s  %s\n" %
                          (maxnamelen, name, place[i], vers[i]))
+                enabledextensions[name] = {
+                    'place': place[i],
+                    'version': vers[i]
+                }
+        fm.data(enabledextensions=enabledextensions)
+    fm.end()
 
 def loadcmdtable(ui, name, cmdtable):
     """Load command functions from specified cmdtable
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -301,7 +301,7 @@
   tip: patch, git, style, template
   unbundle: update
   verify: 
-  version: 
+  version: template
 
   $ hg init a
   $ cd a


More information about the Mercurial-devel mailing list