[gnome-mines] Add --version command-line option.
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mines] Add --version command-line option.
- Date: Tue, 23 Sep 2014 18:43:47 +0000 (UTC)
commit 701f0723b9265d063d58a5a7ee8087ef9b6ecc75
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Jul 14 05:37:52 2014 +0200
Add --version command-line option.
https://bugzilla.gnome.org/show_bug.cgi?id=733162
configure.ac | 2 +-
src/gnome-mines.vala | 41 ++++++++++++++++++++++++-----------------
2 files changed, 25 insertions(+), 18 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b42e4aa..aa62de1 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
diff --git a/src/gnome-mines.vala b/src/gnome-mines.vala
index ffe1e40..d46c105 100644
--- a/src/gnome-mines.vala
+++ b/src/gnome-mines.vala
@@ -73,6 +73,12 @@ public class Mines : Gtk.Application
private Gtk.AspectFrame custom_game_screen;
private bool is_new_game_screen;
+ 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 },
@@ -87,6 +93,8 @@ public class Mines : Gtk.Application
public Mines ()
{
Object (application_id: "org.gnome.mines", flags: ApplicationFlags.FLAGS_NONE);
+
+ add_main_option_entries (option_entries);
}
protected override void startup ()
@@ -362,9 +370,22 @@ public class Mines : Gtk.Application
settings.apply ();
}
- public override void activate ()
+ protected override int handle_local_options (GLib.VariantDict options)
{
- window.show ();
+ if (options.contains ("version"))
+ {
+ /* NOTE: Is not translated so can be easily parsed */
+ stderr.printf ("%1$s %2$s\n", "gnome-mines", VERSION);
+ return Posix.EXIT_SUCCESS;
+ }
+
+ /* Activate */
+ return -1;
+ }
+
+ protected override void activate ()
+ {
+ window.present ();
}
private bool view_button_press_event (Gtk.Widget widget, Gdk.EventButton event)
@@ -783,21 +804,7 @@ public class Mines : 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);
- return Posix.EXIT_FAILURE;
- }
-
var app = new Mines ();
- return app.run ();
+ return app.run (args);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]