[gnome-tetravex] Add --version command-line option.



commit b7b3806a0a474da8e86ea360546c7b4823e1f887
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Jul 14 02:30:45 2014 +0200

    Add --version command-line option.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733126

 configure.ac            |    2 +-
 src/gnome-tetravex.vala |   21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 768ae4d..9d7caaf 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.13.2
 
 PKG_CHECK_MODULES(GNOME_TETRAVEX, [
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index f0580cd..cfef006 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -29,6 +29,12 @@ public class Tetravex : Gtk.Application
     private Gtk.Stack new_game_solve_stack;
     private Gtk.Stack play_pause_stack;
 
+    private const OptionEntry[] option_entries =
+    {
+        { "version", 'v', 0, OptionArg.NONE, null, N_("Print release version and exit"), null },
+        { null }
+    };
+
     private const GLib.ActionEntry[] action_entries =
     {
         { "new-game",      new_game_cb                                            },
@@ -48,6 +54,8 @@ public class Tetravex : Gtk.Application
     public Tetravex ()
     {
         Object (application_id: "org.gnome.tetravex", flags: ApplicationFlags.FLAGS_NONE);
+
+        add_main_option_entries (option_entries);
     }
 
     protected override void startup ()
@@ -214,6 +222,19 @@ public class Tetravex : Gtk.Application
         settings.set_boolean ("window-is-maximized", is_maximized);
     }
 
+    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", "gnome-tetravex", VERSION);
+            return Posix.EXIT_SUCCESS;
+        }
+
+        /* Activate */
+        return -1;
+    }
+
     protected override void activate ()
     {
         window.present ();


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