[glib] Add ‘gsettings list-schemas --print-paths’ option



commit 6d009bc56a4e1d369e906f67188a6338b98ba929
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Jan 5 00:45:57 2018 +0100

    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

 docs/reference/gio/gsettings.xml |    4 ++-
 gio/completion/gsettings         |    4 +++
 gio/gsettings-tool.c             |   43 +++++++++++++++++++++++++++++++++++--
 3 files changed, 47 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/gio/gsettings.xml b/docs/reference/gio/gsettings.xml
index 9528b9d..d7dc65d 100644
--- a/docs/reference/gio/gsettings.xml
+++ b/docs/reference/gio/gsettings.xml
@@ -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>
 
diff --git a/gio/completion/gsettings b/gio/completion/gsettings
index 22b2ac3..d509758 100644
--- a/gio/completion/gsettings
+++ b/gio/completion/gsettings
@@ -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.$.:/.')"
diff --git a/gio/gsettings-tool.c b/gio/gsettings-tool.c
index d74b6dd..57eb838 100644
--- a/gio/gsettings-tool.c
+++ b/gio/gsettings-tool.c
@@ -141,6 +141,35 @@ gsettings_list_schemas (void)
 }
 
 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)
 {
   gchar **schemas;
@@ -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;
 


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