gsettings-tool: Add --version into general usage
[platform/upstream/glib.git] / gio / gsettings-tool.c
index 8398793..fd6d910 100644 (file)
@@ -149,6 +149,15 @@ output_list (const gchar * const *list)
 }
 
 static void
+gsettings_print_version (GSettings   *settings,
+                         const gchar *key,
+                         const gchar *value)
+{
+  g_print ("%d.%d.%d\n", glib_major_version, glib_minor_version,
+           glib_micro_version);
+}
+
+static void
 gsettings_list_schemas (GSettings   *settings,
                         const gchar *key,
                         const gchar *value)
@@ -504,7 +513,11 @@ gsettings_set (GSettings   *settings,
       exit (1);
     }
 
-  g_settings_set_value (settings, key, new);
+  if (!g_settings_set_value (settings, key, new))
+    {
+      g_printerr (_("The key is not writable\n"));
+      exit (1);
+    }
 
   g_settings_sync ();
 
@@ -530,6 +543,12 @@ gsettings_help (gboolean     requested,
       synopsis = "[COMMAND]";
     }
 
+  else if (strcmp (command, "--version") == 0)
+    {
+      description = _("Print version information and exit");
+      synopsis = "";
+    }
+
   else if (strcmp (command, "list-schemas") == 0)
     {
       description = _("List the installed (non-relocatable) schemas");
@@ -615,6 +634,7 @@ gsettings_help (gboolean     requested,
     {
       g_string_append (string,
       _("Usage:\n"
+        "  gsettings --version\n"
         "  gsettings [--schemadir SCHEMADIR] COMMAND [ARGS...]\n"
         "\n"
         "Commands:\n"
@@ -736,6 +756,9 @@ main (int argc, char **argv)
   if (strcmp (argv[1], "help") == 0)
     return gsettings_help (TRUE, argv[2]);
 
+  else if (argc == 2 && strcmp (argv[1], "--version") == 0)
+    function = gsettings_print_version;
+
   else if (argc == 2 && strcmp (argv[1], "list-schemas") == 0)
     function = gsettings_list_schemas;