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

login
register
mail settings
Submitter Iulian Stana
Date April 19, 2013, 12:23 p.m.
Message ID <974f7dab5533feaa46ae.1366374216@doppler>
Download mbox | patch
Permalink /patch/1453/
State Accepted, archived
Headers show

Comments

Iulian Stana - April 19, 2013, 12:23 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@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.
Matt Mackall - April 19, 2013, 8:02 p.m.
On Fri, 2013-04-19 at 15:23 +0300, Iulian Stana wrote:
> # HG changeset patch
> # User Iulian Stana <julian.stana@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.

Looks good. Augie, please queue this in your special
GSoC-features-during-codefreeze queue.
Augie Fackler - April 22, 2013, 8:03 p.m.
On Apr 19, 2013, at 4:02 PM, Matt Mackall <mpm@selenic.com> wrote:

> On Fri, 2013-04-19 at 15:23 +0300, Iulian Stana wrote:
>> # HG changeset patch
>> # User Iulian Stana <julian.stana@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.
> 
> Looks good. Augie, please queue this in your special
> GSoC-features-during-codefreeze queue.

Queued!

(public URL for that coming soon)

Patch

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