[gtk+] gtk-builder-tool: Separate commands



commit d7523423d45a272cf07a9034fc09b0b4dcdb0185
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Apr 27 23:31:03 2015 -0400

    gtk-builder-tool: Separate commands
    
    Add separate commands for validation and simplification.

 docs/reference/gtk/gtk-builder-tool.xml |   22 ++++++++++++++++---
 gtk/gtk-builder-tool.c                  |   35 ++++++++++++++++--------------
 2 files changed, 37 insertions(+), 20 deletions(-)
---
diff --git a/docs/reference/gtk/gtk-builder-tool.xml b/docs/reference/gtk/gtk-builder-tool.xml
index c7cef90..13dedbf 100644
--- a/docs/reference/gtk/gtk-builder-tool.xml
+++ b/docs/reference/gtk/gtk-builder-tool.xml
@@ -30,17 +30,31 @@
 <refsynopsisdiv>
 <cmdsynopsis>
 <command>gtk-builder-tool</command>
+<arg choice="opt"><replaceable>COMMAND</replaceable></arg>
 <arg choice="plain"><replaceable>FILE</replaceable></arg>
 </cmdsynopsis>
 </refsynopsisdiv>
 
 <refsect1><title>Description</title>
 <para>
-  <command>gtk-builder-tool</command> validates and simplifies a GtkBuilder
-  .ui file. Any validation errors are reported on stderr. If the file is
-  valid, it is simplified by removing any properties that are set to their
-  default value. The resulting xml is written to stdout.
+  <command>gtk-builder-tool</command> can perform various operations
+  on GtkBuilder .ui files.
 </para>
 </refsect1>
 
+<refsect1><title>Commands</title>
+  <para>The following commands are understood:</para>
+  <variablelist>
+    <varlistentry>
+    <term><option>validate</option></term>
+      <listitem><para>Validate the .ui file and report errors to stderr.</para></listitem>
+    </varlistentry>
+    <varlistentry>
+    <term><option>simplify</option></term>
+      <listitem><para>Simplify the .ui file by removing properties that
+      are set to their default values and write the resulting XML to stdout.</para></listitem>
+    </varlistentry>
+  </variablelist>
+</refsect1>
+
 </refentry>
diff --git a/gtk/gtk-builder-tool.c b/gtk/gtk-builder-tool.c
index 887df74..c133438 100644
--- a/gtk/gtk-builder-tool.c
+++ b/gtk/gtk-builder-tool.c
@@ -362,7 +362,7 @@ GMarkupParser parser = {
   NULL
 };
 
-static gboolean
+static void
 do_simplify (const gchar *filename)
 {
   GMarkupParseContext *context;
@@ -373,7 +373,7 @@ do_simplify (const gchar *filename)
   if (!g_file_get_contents (filename, &buffer, NULL, &error))
     {
       g_printerr (_("Can't load file: %s\n"), error->message);
-      return FALSE;
+      exit (1);
     }
 
   data.builder = gtk_builder_new ();
@@ -390,13 +390,11 @@ do_simplify (const gchar *filename)
   if (!g_markup_parse_context_parse (context, buffer, -1, &error))
     {
       g_printerr (_("Can't parse file: %s\n"), error->message);
-      return FALSE;
+      exit (1);
     }
-
-  return TRUE;
 }
 
-static gboolean
+static void
 do_validate (const gchar *filename)
 {
   GtkBuilder *builder;
@@ -410,16 +408,20 @@ do_validate (const gchar *filename)
   if (ret == 0)
     {
       g_printerr ("%s\n", error->message);
-      return FALSE;
+      exit (1);
     }
-
-  return TRUE;
 }
 
 static void
 usage (void)
 {
-  g_print (_("Usage: gtk-builder-tool FILE\n"
+  g_print (_("Usage:\n"
+             "  gtk-builder-tool [COMMAND] FILE\n"
+             "\n"
+             "Commands:\n"
+             "  validate    Validate the file\n"
+             "  simplify    Simplify the file\n"
+             "\n"
              "Validate and simplify GtkBuilder .ui files.\n"));
   exit (1);
 }
@@ -433,14 +435,15 @@ main (int argc, char *argv[])
 
   gtk_test_register_all_types ();
 
-  if (argc < 2)
+  if (argc < 3)
     usage ();
 
-  if (!do_validate (argv[1]))
-    return 1;
-
-  if (!do_simplify (argv[1]))
-    return 1;
+  if (strcmp (argv[1], "validate") == 0)
+    do_validate (argv[2]);
+  else if (strcmp (argv[1], "simplify") == 0)
+    do_simplify (argv[2]);
+  else
+    usage ();
 
   return 0;
 }


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