[PATCH V2] templater: show the style list when I try to use a wrong one

Iulian Stana julian.stana at gmail.com
Fri Apr 19 07:23:36 CDT 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1366312898 -10800
#      Thu Apr 18 22:21:38 2013 +0300
# Node ID 974f7dab5533feaa46aec5970d40a0f94f77175e
# Parent  7d31f2e42a8afb54c8fae87e8e3e29a63578aea4
templater: show the style list when I try to use a wrong one

When someone try to use a wrong style, a list with sugestions will appear.

In the test-log.t file it's a test that prove this thing.

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -392,6 +392,16 @@
 
 engines = {'default': engine}
 
+def stylelist():
+    path = templatepath()[0]
+    dirlist =  os.listdir(path)
+    stylelist = []
+    for file in dirlist:
+        split = file.split(".")
+        if split[0] == "map-cmdline":
+            stylelist.append(split[1])
+    return ", ".join(stylelist)
+
 class templater(object):
 
     def __init__(self, mapfile, filters={}, defaults={}, cache={},
@@ -413,7 +423,8 @@
         if not mapfile:
             return
         if not os.path.exists(mapfile):
-            raise util.Abort(_('style not found: %s') % mapfile)
+            raise util.Abort(_("style '%s' not found") % mapfile,
+                             hint=_("available styles: %s") % stylelist())
 
         conf = config.config()
         conf.read(mapfile)
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -84,6 +84,14 @@
   abort: cannot follow file not in parent revision: "dir"
   [255]
 
+-f, a wrong style
+
+  $ hg log -f -l1 --style something
+  abort: style 'something' not found
+  (available styles: changelog, bisect, default, xml, compact)
+  [255]
+
+
 -f, but no args
 
   $ hg log -f


More information about the Mercurial-devel mailing list