Add ‘gsettings list-schemas --print-paths’ option

Prints next to the name of non-relocatable schemas their paths.

https://bugzilla.gnome.org/show_bug.cgi?id=792064
This commit is contained in:
Arnaud Bonatti 2018-01-05 00:45:57 +01:00 committed by Philip Withnall
parent 617d40c13b
commit 6d009bc56a
3 changed files with 47 additions and 4 deletions

View File

@ -75,6 +75,7 @@
<cmdsynopsis>
<command>gsettings</command>
<arg choice="plain">list-schemas</arg>
<arg choice="opt">--print-paths</arg>
</cmdsynopsis>
<cmdsynopsis>
<command>gsettings</command>
@ -198,7 +199,8 @@ Reset all keys under the given <replaceable>SCHEMA</replaceable>.
<listitem><para>
Lists the installed, non-relocatable schemas.
See <option>list-relocatable-schemas</option> if you are interested in
relocatable schemas.
relocatable schemas. If <optional><option>--print-paths</option></optional>
is given, the path where each schema is mapped is also printed.
</para></listitem>
</varlistentry>

View File

@ -37,6 +37,10 @@ __gsettings() {
list-keys|list-children|list-recursively|reset-recursively)
choices="$(gsettings $schemadir list-schemas 2> /dev/null)"$'\n'"$(gsettings $schemadir list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"
;;
list-schemas)
COMPREPLY=($(compgen -W "--print-paths" -- ${COMP_WORDS[${COMP_CWORD}]}))
return 0
;;
get|range|set|reset|writable|monitor|describe)
choices="$(gsettings $schemadir list-schemas 2> /dev/null | sed -e 's.$. .')"$'\n'"$(gsettings $schemadir list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"

View File

@ -140,6 +140,35 @@ gsettings_list_schemas (void)
g_strfreev (schemas);
}
static void
gsettings_list_schemas_with_paths (void)
{
gchar **schemas;
gsize i;
g_settings_schema_source_list_schemas (global_schema_source, TRUE, &schemas, NULL);
for (i = 0; schemas[i] != NULL; i++)
{
GSettingsSchema *schema;
gchar *schema_name;
const gchar *schema_path;
schema_name = g_steal_pointer (&schemas[i]);
schema = g_settings_schema_source_lookup (global_schema_source, schema_name, TRUE);
schema_path = g_settings_schema_get_path (schema);
schemas[i] = g_strconcat (schema_name, " ", schema_path, NULL);
g_settings_schema_unref (schema);
g_free (schema_name);
}
output_list (schemas);
g_strfreev (schemas);
}
static void
gsettings_list_relocatable_schemas (void)
{
@ -532,7 +561,7 @@ gsettings_help (gboolean requested,
else if (strcmp (command, "list-schemas") == 0)
{
description = _("List the installed (non-relocatable) schemas");
synopsis = "";
synopsis = "[--print-paths]";
}
else if (strcmp (command, "list-relocatable-schemas") == 0)
@ -690,7 +719,7 @@ int
main (int argc, char **argv)
{
void (* function) (void);
gboolean need_settings;
gboolean need_settings, skip_third_arg_test;
#ifdef G_OS_WIN32
gchar *tmp;
@ -744,6 +773,7 @@ main (int argc, char **argv)
g_settings_schema_source_ref (global_schema_source);
need_settings = TRUE;
skip_third_arg_test = FALSE;
if (strcmp (argv[1], "help") == 0)
return gsettings_help (TRUE, argv[2]);
@ -754,6 +784,13 @@ main (int argc, char **argv)
else if (argc == 2 && strcmp (argv[1], "list-schemas") == 0)
function = gsettings_list_schemas;
else if (argc == 3 && strcmp (argv[1], "list-schemas") == 0
&& strcmp (argv[2], "--print-paths") == 0)
{
skip_third_arg_test = TRUE;
function = gsettings_list_schemas_with_paths;
}
else if (argc == 2 && strcmp (argv[1], "list-relocatable-schemas") == 0)
function = gsettings_list_relocatable_schemas;
@ -802,7 +839,7 @@ main (int argc, char **argv)
else
return gsettings_help (FALSE, argv[1]);
if (argc > 2)
if (argc > 2 && !skip_third_arg_test)
{
gchar **parts;