[gnome-klotski/wip/mallard-help-merge: 63/92] Add --version command-line option.



commit c101b1c05d5b4bd78dc69735af0487af352226b6
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Jul 15 12:32:35 2014 +0200

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

 configure.ac           |    2 ++
 data/gnome-klotski.6   |    7 ++-----
 src/gnome-klotski.vala |   35 +++++++++++++++++++++--------------
 3 files changed, 25 insertions(+), 19 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index faaaa65..e93492c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,10 +15,12 @@ dnl ###########################################################################
 dnl Dependencies
 dnl ###########################################################################
 
+GLIB_REQUIRED=2.40.0
 GTK_REQUIRED=3.10.0
 RSVG_REQUIRED=2.32.0
 
 PKG_CHECK_MODULES(GNOME_KLOTSKI, [
+  glib-2.0 >= $GLIB_REQUIRED
   gtk+-3.0 >= $GTK_REQUIRED
   librsvg-2.0 >= $RSVG_REQUIRED
 ])
diff --git a/data/gnome-klotski.6 b/data/gnome-klotski.6
index a065609..dd5197a 100644
--- a/data/gnome-klotski.6
+++ b/data/gnome-klotski.6
@@ -25,11 +25,8 @@ is a clone of the Klotski game. The objective is to move the patterned
 block to the area bordered by green markers.
 .SH OPTIONS
 .TP
-.B \-x, \-\-x=X
-X location of window
-.TP
-.B \-y, \-\-y=Y
-Y location of window
+.B \-v, \-\-version
+Print release version and exit
 .P
 This program also accepts the standard GNOME and GTK options.
 .SH AUTHORS
diff --git a/src/gnome-klotski.vala b/src/gnome-klotski.vala
index 5bc0cbd..9572377 100644
--- a/src/gnome-klotski.vala
+++ b/src/gnome-klotski.vala
@@ -429,6 +429,12 @@ public class Klotski : Gtk.Application
        "#################"}
     };
 
+    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",             restart_level_cb  },
@@ -444,6 +450,8 @@ public class Klotski : Gtk.Application
     public Klotski ()
     {
         Object (application_id: "org.gnome.klotski", flags: ApplicationFlags.FLAGS_NONE);
+
+        add_main_option_entries (option_entries);
     }
 
     protected override void startup ()
@@ -895,6 +903,19 @@ public class Klotski : 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-klotski", VERSION);
+            return Posix.EXIT_SUCCESS;
+        }
+
+        /* Activate */
+        return -1;
+    }
+
     protected override void activate ()
     {
         window.present ();
@@ -928,20 +949,6 @@ public class Klotski : Gtk.Application
         Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
         Intl.textdomain (GETTEXT_PACKAGE);
 
-        var context = new OptionContext (null);
-        context.set_translation_domain (GETTEXT_PACKAGE);
-        context.add_group (Gtk.get_option_group (true));
-
-        try
-        {
-            context.parse (ref args);
-        }
-        catch (Error e)
-        {
-            stderr.printf ("%s\n", e.message);
-            Posix.exit (Posix.EXIT_FAILURE);
-        }
-
         var app = new Klotski ();
         return app.run (args);
     }


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