##// END OF EJS Templates
version: add formatter support...
Yuya Nishihara -
r29840:4435d4c9 default
parent child Browse files
Show More
@@ -7241,36 +7241,49 b' def verify(ui, repo):'
7241 7241 """
7242 7242 return hg.verify(repo)
7243 7243
7244 @command('version', [], norepo=True)
7245 def version_(ui):
7244 @command('version', [] + formatteropts, norepo=True)
7245 def version_(ui, **opts):
7246 7246 """output version and copyright information"""
7247 ui.write(_("Mercurial Distributed SCM (version %s)\n")
7248 % util.version())
7249 ui.status(_(
7247 fm = ui.formatter("version", opts)
7248 fm.startitem()
7249 fm.write("ver", _("Mercurial Distributed SCM (version %s)\n"),
7250 util.version())
7251 license = _(
7250 7252 "(see https://mercurial-scm.org for more information)\n"
7251 7253 "\nCopyright (C) 2005-2016 Matt Mackall and others\n"
7252 7254 "This is free software; see the source for copying conditions. "
7253 7255 "There is NO\nwarranty; "
7254 7256 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
7255 ))
7256
7257 ui.note(_("\nEnabled extensions:\n\n"))
7257 )
7258 if not ui.quiet:
7259 fm.plain(license)
7260
7261 if ui.verbose:
7262 fm.plain(_("\nEnabled extensions:\n\n"))
7258 7263 # format names and versions into columns
7259 7264 names = []
7260 7265 vers = []
7261 7266 isinternals = []
7262 7267 for name, module in extensions.extensions():
7263 7268 names.append(name)
7264 vers.append(extensions.moduleversion(module))
7269 vers.append(extensions.moduleversion(module) or None)
7265 7270 isinternals.append(extensions.ismoduleinternal(module))
7271 fn = fm.nested("extensions")
7266 7272 if names:
7267 maxnamelen = max(len(n) for n in names)
7268 places = [_("external"), _("internal")]
7269 for i, name in enumerate(names):
7270 p = isinternals[i]
7273 namefmt = " %%-%ds " % max(len(n) for n in names)
7274 if fn:
7275 places = ["external", "internal"]
7276 else:
7277 places = [_("external"), _("internal")]
7278 for n, v, p in zip(names, vers, isinternals):
7279 fn.startitem()
7280 fn.condwrite(ui.verbose, "name", namefmt, n)
7281 fn.condwrite(ui.verbose, "place", "%s ", places[p])
7282 fn.condwrite(ui.verbose and v, "ver", "%s", v)
7271 7283 if ui.verbose:
7272 ui.write(" %-*s %s %s\n" %
7273 (maxnamelen, name, places[p], vers[i]))
7284 fn.plain("\n")
7285 fn.end()
7286 fm.end()
7274 7287
7275 7288 def loadcmdtable(ui, name, cmdtable):
7276 7289 """Load command functions from specified cmdtable
@@ -301,7 +301,7 b' Show all commands + options'
301 301 tip: patch, git, style, template
302 302 unbundle: update
303 303 verify:
304 version:
304 version: template
305 305
306 306 $ hg init a
307 307 $ cd a
@@ -1240,6 +1240,39 b" Test version number support in 'hg versi"
1240 1240 $ hg version -q --config extensions.throw=throw.py
1241 1241 Mercurial Distributed SCM (version *) (glob)
1242 1242
1243 Test JSON output of version:
1244
1245 $ hg version -Tjson
1246 [
1247 {
1248 "extensions": [],
1249 "ver": "*" (glob)
1250 }
1251 ]
1252
1253 $ hg version --config extensions.throw=throw.py -Tjson
1254 [
1255 {
1256 "extensions": [{"name": "throw", "place": "external", "ver": "1.twentythree"}],
1257 "ver": "3.2.2"
1258 }
1259 ]
1260
1261 $ LANGUAGE= LC_ALL=ja_JP.UTF-8 hg version --config extensions.strip= -Tjson
1262 [
1263 {
1264 "extensions": [{"name": "strip", "place": "internal", "ver": null}],
1265 "ver": "*" (glob)
1266 }
1267 ]
1268
1269 Test template output of version:
1270
1271 $ hg version --config extensions.throw=throw.py --config extensions.strip= \
1272 > -T'{extensions % "{name} {pad(ver, 16)} ({place})\n"}'
1273 throw 1.twentythree (external)
1274 strip (internal)
1275
1243 1276 Refuse to load extensions with minimum version requirements
1244 1277
1245 1278 $ cat > minversion1.py << EOF
General Comments 0
You need to be logged in to leave comments. Login now