[gegl] gegl-chain: suggest possible ops in warninge/errors



commit 1e4498dffe23c924a35acb24c6aa0ae4cf4538b4
Author: Øyvind Kolås <pippin gimp org>
Date:   Sat Apr 16 10:32:39 2016 +0100

    gegl-chain: suggest possible ops in warninge/errors

 gegl/gegl-serialize.c         |   41 +++++++++++++++++++++++++++++++++++++++--
 tests/simple/test-serialize.c |    1 +
 2 files changed, 40 insertions(+), 2 deletions(-)
---
diff --git a/gegl/gegl-serialize.c b/gegl/gegl-serialize.c
index 674e85e..87343c9 100644
--- a/gegl/gegl-serialize.c
+++ b/gegl/gegl-serialize.c
@@ -242,7 +242,8 @@ void gegl_create_chain_argv (char **ops, GeglNode *start, GeglNode *proxy, doubl
           else if (error)
           {
             GString *str = g_string_new ("");
-            g_string_append_printf (str, "No such op '%s'", level_op[level]);
+            g_string_append_printf (str, "op '%s' not found, partial matches: ", level_op[level]);
+
             *error = g_error_new_literal (g_quark_from_static_string ("gegl"),
                                           0, str->str);
              g_string_free (str, TRUE);
@@ -415,10 +416,46 @@ void gegl_create_chain_argv (char **ops, GeglNode *start, GeglNode *proxy, doubl
           else if (error)
           {
             GString *str = g_string_new ("");
+            guint    n_operations;
+            gchar  **operations = gegl_list_operations (&n_operations);
+            gint     i;
+            gint     started = 0;
+            gint     max = 12;
+
             g_string_append_printf (str, "No such op '%s'", level_op[level]);
+
+            for (i = 0; i < n_operations; i++)
+            {
+              if (g_str_has_prefix (operations[i], level_op[level]))
+              {
+                if (!started)
+                {
+                  started = 1;
+                  g_string_append_printf (str," suggestions:");
+                }
+                if (max -- > 0)
+                  g_string_append_printf (str, " %s", operations[i]);
+              }
+            }
+            if (!started)
+            for (i = 0; i < n_operations; i++)
+            {
+              if (strstr (operations[i], *arg))
+              {
+                if (!started)
+                {
+                  started = 1;
+                  g_string_append_printf (str," suggestions:");
+                }
+                if (max -- > 0)
+                  g_string_append_printf (str, " %s", operations[i]);
+              }
+            }
+
+            g_free (operations);
             *error = g_error_new_literal (g_quark_from_static_string ("gegl"),
                                           0, str->str);
-             g_string_free (str, TRUE);
+            g_string_free (str, TRUE);
           }
 
       }
diff --git a/tests/simple/test-serialize.c b/tests/simple/test-serialize.c
index cc4d93b..6d5abd6 100644
--- a/tests/simple/test-serialize.c
+++ b/tests/simple/test-serialize.c
@@ -55,6 +55,7 @@ TestCase tests[] = {
 #if 0
     {"over aux=[]",  " svg:src-over", "No such op 'gegl:['"},  /* should report error message */
 #endif
+    {"inver",           "", "No such op 'gegl:inver' suggestions: gegl:invert-gamma gegl:invert-linear"},
     {NULL, NULL}
 };
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]