paths: Add support for -q/--quiet
authorThomas Arendsen Hein <thomas@intevation.de>
Mon, 16 May 2011 11:41:48 +0200
changeset 14331 3b9a896af09c
parent 14330 473d0aaf7655
child 14332 a2f0f61a6988
paths: Add support for -q/--quiet Suppresses output (resolved paths or "not found!") when searching a path, similar to "grep -q". Sample usage: hg paths -q foo || echo "there is no foo" Just prints path names (instead of "name = result") when listing all path definitions, like "hg bookmarks -q". Sample usage: hg paths -q | while read i; do hg incoming "$i"; done
mercurial/commands.py
tests/test-paths.t
--- a/mercurial/commands.py	Mon May 16 11:14:06 2011 +0200
+++ b/mercurial/commands.py	Mon May 16 11:41:48 2011 +0200
@@ -3591,6 +3591,9 @@
     Show definition of symbolic path name NAME. If no name is given,
     show definition of all available names.
 
+    Option -q/--quiet suppresses all output when searching for NAME
+    and shows only the path names when listing all definitions.
+
     Path names are defined in the [paths] section of your
     configuration file and in ``/etc/mercurial/hgrc``. If run inside a
     repository, ``.hg/hgrc`` is used, too.
@@ -3613,13 +3616,17 @@
     if search:
         for name, path in ui.configitems("paths"):
             if name == search:
-                ui.write("%s\n" % util.hidepassword(path))
+                ui.status("%s\n" % util.hidepassword(path))
                 return
-        ui.warn(_("not found!\n"))
+        if not ui.quiet:
+            ui.warn(_("not found!\n"))
         return 1
     else:
         for name, path in ui.configitems("paths"):
-            ui.write("%s = %s\n" % (name, util.hidepassword(path)))
+            if ui.quiet:
+                ui.write("%s\n" % name)
+            else:
+                ui.write("%s = %s\n" % (name, util.hidepassword(path)))
 
 def postincoming(ui, repo, modheads, optupdate, checkout):
     if modheads == 0:
--- a/tests/test-paths.t	Mon May 16 11:14:06 2011 +0200
+++ b/tests/test-paths.t	Mon May 16 11:41:48 2011 +0200
@@ -25,6 +25,17 @@
   $ SOMETHING=/foo hg paths
   dupe = $TESTTMP/b
   expand = /foo/bar
+  $ hg paths -q
+  dupe
+  expand
+  $ hg paths dupe
+  $TESTTMP/b
+  $ hg paths -q dupe
+  $ hg paths unknown
+  not found!
+  [1]
+  $ hg paths -q unknown
+  [1]
   $ cd ..
 
 'file:' disables [paths] entries for clone destination