changeset 42418:9803323048b6

root: add support for -Tformatter option It's useless right now, but it should just work and I want to add a few more fields.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 04 Jun 2019 20:58:39 +0900
parents a97b12f726e4
children 69883775b27d
files mercurial/commands.py tests/test-alias.t tests/test-basic.t tests/test-completion.t tests/test-help.t
diffstat 5 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu May 23 03:03:36 2019 +0530
+++ b/mercurial/commands.py	Tue Jun 04 20:58:39 2019 +0900
@@ -5225,16 +5225,19 @@
                          force=opts.get(r'force'))
 
 @command(
-    'root', [], intents={INTENT_READONLY},
+    'root', [] + formatteropts, intents={INTENT_READONLY},
     helpcategory=command.CATEGORY_WORKING_DIRECTORY)
-def root(ui, repo):
+def root(ui, repo, **opts):
     """print the root (top) of the current working directory
 
     Print the root directory of the current repository.
 
     Returns 0 on success.
     """
-    ui.write(repo.root + "\n")
+    opts = pycompat.byteskwargs(opts)
+    with ui.formatter('root', opts) as fm:
+        fm.startitem()
+        fm.write('reporoot', '%s\n', repo.root)
 
 @command('serve',
     [('A', 'accesslog', '', _('name of access log file to write to'),
--- a/tests/test-alias.t	Thu May 23 03:03:36 2019 +0530
+++ b/tests/test-alias.t	Tue Jun 04 20:58:39 2019 +0900
@@ -645,6 +645,10 @@
   
   alias for: hg root
   
+  options:
+  
+   -T --template TEMPLATE display with template
+  
   (use 'hg rt -h' to show more help)
   [255]
 
--- a/tests/test-basic.t	Thu May 23 03:03:36 2019 +0530
+++ b/tests/test-basic.t	Tue Jun 04 20:58:39 2019 +0900
@@ -98,6 +98,12 @@
   $TESTTMP/t
   $ hg log -l1 -T '{reporoot}\n'
   $TESTTMP/t
+  $ hg root -Tjson | sed 's|\\\\|\\|g'
+  [
+   {
+    "reporoot": "$TESTTMP/t"
+   }
+  ]
 
 At the end...
 
--- a/tests/test-completion.t	Thu May 23 03:03:36 2019 +0530
+++ b/tests/test-completion.t	Tue Jun 04 20:58:39 2019 +0900
@@ -338,7 +338,7 @@
   resolve: all, list, mark, unmark, no-status, re-merge, tool, include, exclude, template
   revert: all, date, rev, no-backup, interactive, include, exclude, dry-run
   rollback: dry-run, force
-  root: 
+  root: template
   serve: accesslog, daemon, daemon-postexec, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate, print-url, subrepos
   status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, terse, copies, print0, rev, change, include, exclude, subrepos, template
   summary: remote
--- a/tests/test-help.t	Thu May 23 03:03:36 2019 +0530
+++ b/tests/test-help.t	Tue Jun 04 20:58:39 2019 +0900
@@ -557,6 +557,10 @@
   
       Returns 0 on success.
   
+  options:
+  
+   -T --template TEMPLATE display with template
+  
   (some details hidden, use --verbose to show
   complete help)