Commit df5b4827 authored by Matthias Clasen's avatar Matthias Clasen

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.
parent 3d9727c0
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment