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

Iulian Stana julian.stana at gmail.com
Thu Apr 18 13:13:00 CDT 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1366228237 -10800
#      Wed Apr 17 22:50:37 2013 +0300
# Node ID cacb96e80ea80ef623589c171e81911205777265
# Parent  186c1300c10d40b4d6871e851b57d8d44368dcb0
log-style: 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 -r 186c1300c10d -r cacb96e80ea8 mercurial/templater.py
--- a/mercurial/templater.py	Tue Apr 16 22:09:28 2013 +0300
+++ b/mercurial/templater.py	Wed Apr 17 22:50:37 2013 +0300
@@ -391,6 +391,21 @@
 
 engines = {'default': engine}
 
+def stylelist():
+    path = templatepath()[0]
+    dirlist =  os.listdir(path)
+    stylelist = ''
+    notfirst = False
+    for file in dirlist:
+        split = file.split(".")
+        if split[0] == "map-cmdline":
+            if notfirst == True:
+                stylelist = stylelist + ','
+            else:
+                notfirst = True
+            stylelist = stylelist + ' ' + split[1]
+    return stylelist
+
 class templater(object):
 
     def __init__(self, mapfile, filters={}, defaults={}, cache={},
@@ -412,7 +427,7 @@
         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 \n(available styles:%s)") % (mapfile,stylelist()))
 
         conf = config.config()
         conf.read(mapfile)
diff -r 186c1300c10d -r cacb96e80ea8 tests/test-log.t
--- a/tests/test-log.t	Tue Apr 16 22:09:28 2013 +0300
+++ b/tests/test-log.t	Wed Apr 17 22:50:37 2013 +0300
@@ -67,7 +67,7 @@
   abort: cannot follow file not in parent revision: "dir"
   [255]
 
--f, one
+-f, phases style
 
   $ hg log -f -l1 --style phases
   changeset:   4:7e4639b4691b
@@ -78,6 +78,16 @@
   summary:     e
   
 
+-f, a wrong style
+
+  $ hg log -f -l1 --style something
+  abort: style 'something' not found 
+  (available styles: changelog, bisect, default, xml, phases, compact)
+  [255]
+
+
+
+
 -f, but no args
 
   $ hg log -f


More information about the Mercurial-devel mailing list