Patchwork [1,of,2] root: add support for -Tformatter option

login
register
mail settings
Submitter Yuya Nishihara
Date June 4, 2019, 11:30 p.m.
Message ID <7182320ee57475303eb6.1559691047@mimosa>
Download mbox | patch
Permalink /patch/40318/
State New
Headers show

Comments

Yuya Nishihara - June 4, 2019, 11:30 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1559649519 -32400
#      Tue Jun 04 20:58:39 2019 +0900
# Node ID 7182320ee57475303eb677a41dde142b7f87fc9b
# Parent  4738c292a52072cc6f6a54b5d4066720509dec55
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.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5225,16 +5225,19 @@  def rollback(ui, repo, **opts):
                          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'),
diff --git a/tests/test-alias.t b/tests/test-alias.t
--- a/tests/test-alias.t
+++ b/tests/test-alias.t
@@ -645,6 +645,10 @@  invalid arguments
   
   alias for: hg root
   
+  options:
+  
+   -T --template TEMPLATE display with template
+  
   (use 'hg rt -h' to show more help)
   [255]
 
diff --git a/tests/test-basic.t b/tests/test-basic.t
--- a/tests/test-basic.t
+++ b/tests/test-basic.t
@@ -98,6 +98,12 @@  Repository root:
   $TESTTMP/t
   $ hg log -l1 -T '{reporoot}\n'
   $TESTTMP/t
+  $ hg root -Tjson | sed 's|\\\\|\\|g'
+  [
+   {
+    "reporoot": "$TESTTMP/t"
+   }
+  ]
 
 At the end...
 
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -338,7 +338,7 @@  Show all commands + options
   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
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -557,6 +557,10 @@  Test the textwidth config option
   
       Returns 0 on success.
   
+  options:
+  
+   -T --template TEMPLATE display with template
+  
   (some details hidden, use --verbose to show
   complete help)