[glib/gio-extension-point-help: 12/13] gio: Support "help" in extension point env vars



commit df5b482781b4c465c19447d0c43cd26096d2252b
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jan 20 20:39:57 2019 -0500

    gio: Support "help" in extension point env vars
    
    Interpret the value "help" for environment variables that
    are passed to _g_io_module_get_default(), and print the
    names and priorities of available extensions.
    
    This lets users explore what is available, and can be helpful
    in figuring out why a certain extension was chosen as default.
    
    It is similar in spirit to what we already do with environment
    variables like G_DEBUG.

 gio/giomodule.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
---
diff --git a/gio/giomodule.c b/gio/giomodule.c
index 91334cd15..52c60c210 100644
--- a/gio/giomodule.c
+++ b/gio/giomodule.c
@@ -700,6 +700,35 @@ try_class (GIOExtension *extension,
   return NULL;
 }
 
+static void
+print_help (const char        *envvar,
+            GIOExtensionPoint *ep)
+{
+  g_print ("Supported arguments for %s environment variable:\n", envvar);
+
+  if (g_io_extension_point_get_extensions (ep) == NULL)
+    g_print (" (none)\n");
+  else
+    {
+      GList *l;
+      GIOExtension *extension;
+      int width = 0;
+
+      for (l = g_io_extension_point_get_extensions (ep); l; l = l->next)
+        {
+          extension = l->data;
+          width = MAX (width, strlen (g_io_extension_get_name (extension)));
+        }
+
+      for (l = g_io_extension_point_get_extensions (ep); l; l = l->next)
+        {
+          extension = l->data;
+
+          g_print (" %*s - %d\n", width, g_io_extension_get_name (extension), g_io_extension_get_priority 
(extension));
+        }
+    }
+}
+
 /**
  * _g_io_module_get_default_type:
  * @extension_point: the name of an extension point
@@ -766,6 +795,12 @@ _g_io_module_get_default_type (const gchar *extension_point,
     }
 
   use_this = envvar ? g_getenv (envvar) : NULL;
+  if (g_strcmp0 (use_this, "help") == 0)
+    {
+      print_help (envvar, ep);
+      use_this = NULL;
+    }
+
   if (use_this)
     {
       preferred = g_io_extension_point_get_extension_by_name (ep, use_this);
@@ -909,6 +944,12 @@ _g_io_module_get_default (const gchar         *extension_point,
     }
 
   use_this = envvar ? g_getenv (envvar) : NULL;
+  if (g_strcmp0 (use_this, "help") == 0)
+    {
+      print_help (envvar, ep);
+      use_this = NULL;
+    }
+
   if (use_this)
     {
       preferred = g_io_extension_point_get_extension_by_name (ep, use_this);
@@ -920,7 +961,7 @@ _g_io_module_get_default (const gchar         *extension_point,
            goto done;
        }
       else
-       g_warning ("Can't find module '%s' specified in %s", use_this, envvar);
+        g_warning ("Can't find module '%s' specified in %s", use_this, envvar);
     }
   else
     preferred = NULL;


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