[iagno] Use handle_local_options() for the command-line options.



commit 730984eab0ec88d3855b28801638c496ba4ccf76
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Jul 15 18:28:36 2014 +0200

    Use handle_local_options() for the command-line options.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733224

 configure.ac    |    2 +-
 data/iagno.6    |    2 +-
 src/Makefile.am |    2 +-
 src/iagno.vala  |   60 ++++++++++++++++++++++++------------------------------
 4 files changed, 30 insertions(+), 36 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1dd4688..2614298 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,7 +15,7 @@ dnl ###########################################################################
 dnl Dependencies
 dnl ###########################################################################
 
-GLIB_REQUIRED=2.36.0
+GLIB_REQUIRED=2.40.0
 GTK_REQUIRED=3.12
 RSVG_REQUIRED=2.32.0
 CANBERRA_GTK_REQUIRED=0.26
diff --git a/data/iagno.6 b/data/iagno.6
index d0ddf80..49bb1d8 100644
--- a/data/iagno.6
+++ b/data/iagno.6
@@ -34,7 +34,7 @@ Play with reduced delay before the computer moves.
 .B \-h, \-\-help
 Prints the command line options and exits.
 .TP
-.B \-\-version
+.B \-v, \-\-version
 Prints the program version and exits.
 .P
 This program also accepts the standard GTK+ options.
diff --git a/src/Makefile.am b/src/Makefile.am
index 6e61c74..1ecc089 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,7 +24,7 @@ iagno_VALAFLAGS = \
        --pkg librsvg-2.0 \
        --pkg libcanberra \
        --pkg libcanberra-gtk \
-       --target-glib 2.36
+       --target-glib 2.40
 
 iagno_LDADD = $(IAGNO_LIBS)
 
diff --git a/src/iagno.vala b/src/iagno.vala
index 2a29a0c..1e35fa2 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -42,6 +42,17 @@ public class Iagno : Gtk.Application
     /* The game being played */
     private Game? game = null;
 
+    private static const OptionEntry[] option_entries =
+    {
+        { "fast-mode", 'f', 0, OptionArg.NONE, ref fast_mode,
+          /* Help string for command line --fast-mode flag */
+          N_("Reduce delay before AI moves"), null},
+        { "version", 'v', 0, OptionArg.NONE, null,
+          /* Help string for command line --version flag */
+          N_("Print release version and exit"), null},
+        { null }
+    };
+
     private const GLib.ActionEntry app_actions[] =
     {
         {"new-game", new_game_cb},
@@ -61,6 +72,8 @@ public class Iagno : Gtk.Application
     public Iagno ()
     {
         Object (application_id: "org.gnome.iagno", flags: ApplicationFlags.FLAGS_NONE);
+
+        add_main_option_entries (option_entries);
     }
 
     protected override void activate ()
@@ -167,6 +180,19 @@ public class Iagno : Gtk.Application
         window.show ();
     }
 
+    protected override int handle_local_options (GLib.VariantDict options)
+    {
+        if (options.contains ("version"))
+        {
+            /* NOTE: Is not translated so can be easily parsed */
+            stderr.printf ("%1$s %2$s\n", "iagno", VERSION);
+            return Posix.EXIT_SUCCESS;
+        }
+
+        /* Activate */
+        return -1;
+    }
+
     protected override void shutdown ()
     {
         base.shutdown ();
@@ -606,17 +632,6 @@ public class Iagno : Gtk.Application
         propbox.show_all ();
     }
 
-    private static const OptionEntry[] options =
-    {
-        { "fast-mode", 'f', 0, OptionArg.NONE, ref fast_mode,
-          /* Help string for command line --fast-mode flag */
-          N_("Reduce delay before AI moves"), null},
-        { "version", 'v', 0, OptionArg.NONE, ref show_version,
-          /* Help string for command line --version flag */
-          N_("Show release version"), null},
-        { null }
-    };
-
     public static int main (string[] args)
     {
         Intl.setlocale (LocaleCategory.ALL, "");
@@ -624,34 +639,13 @@ public class Iagno : Gtk.Application
         Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
         Intl.textdomain (GETTEXT_PACKAGE);
 
-        var context = new OptionContext (null);
-        context.add_main_entries (options, GETTEXT_PACKAGE);
-        context.add_group (Gtk.get_option_group (true));
-
-        try
-        {
-            context.parse (ref args);
-        }
-        catch (Error e)
-        {
-            stderr.printf ("%s\n", e.message);
-            return Posix.EXIT_FAILURE;
-        }
-
-        if (show_version)
-        {
-            /* Note, not translated so can be easily parsed */
-            stderr.printf ("iagno %s\n", VERSION);
-            return Posix.EXIT_SUCCESS;
-        }
-
         Environment.set_application_name (_("Iagno"));
 
         Gtk.Window.set_default_icon_name ("iagno");
 
         var app = new Iagno ();
 
-        var result = app.run ();
+        var result = app.run (args);
 
         return result;
     }


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