[gnome-mahjongg] Add --version command-line option.
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-mahjongg] Add --version command-line option.
- Date: Thu, 17 Jul 2014 13:41:56 +0000 (UTC)
commit 19ddf256b14b28fdc54050f5a9f70f5a9a877e21
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Jul 17 15:25:13 2014 +0200
Add --version command-line option.
https://bugzilla.gnome.org/show_bug.cgi?id=733211
configure.ac | 2 ++
data/gnome-mahjongg.6 | 6 +++++-
src/gnome-mahjongg.vala | 39 ++++++++++++++++++++++-----------------
3 files changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0c1ca4c..deac118 100644
--- a/configure.ac
+++ b/configure.ac
@@ -15,10 +15,12 @@ dnl ###########################################################################
dnl Dependencies
dnl ###########################################################################
+GLIB_REQUIRED=2.40.0
GTK_REQUIRED=3.13.2
RSVG_REQUIRED=2.32.0
PKG_CHECK_MODULES(GNOME_MAHJONGG, [
+ glib-2.0 >= $GLIB_REQUIRED
gio-2.0
gtk+-3.0 >= $GTK_REQUIRED
librsvg-2.0 >= $RSVG_REQUIRED
diff --git a/data/gnome-mahjongg.6 b/data/gnome-mahjongg.6
index 191a585..01d5334 100644
--- a/data/gnome-mahjongg.6
+++ b/data/gnome-mahjongg.6
@@ -23,7 +23,11 @@ Mahjongg \- A matching game played with Mahjongg tiles
GNOME Mahjongg, or Mahjongg for short, is a solitaire (one player)
version of the classic Eastern tile game, Mahjongg.
.SH OPTIONS
-This program only accepts the standard GNOME and GTK options.
+.TP
+.B \-v, \-\-version
+Print release version and exit
+.P
+This program also accepts the standard GNOME and GTK options.
.SH AUTHORS
.B mahjongg
was written by Francisco Bustamante, Max Watson and many others.
diff --git a/src/gnome-mahjongg.vala b/src/gnome-mahjongg.vala
index 8ff81e0..fc5e1e2 100644
--- a/src/gnome-mahjongg.vala
+++ b/src/gnome-mahjongg.vala
@@ -28,6 +28,12 @@ public class Mahjongg : Gtk.Application
private Gtk.Label clock_label;
private Gtk.Dialog? preferences_dialog = null;
+ 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 },
@@ -47,6 +53,8 @@ public class Mahjongg : Gtk.Application
public Mahjongg ()
{
Object (application_id: "org.gnome.gnome-mahjongg", flags: ApplicationFlags.FLAGS_NONE);
+
+ add_main_option_entries (option_entries);
}
protected override void startup ()
@@ -238,6 +246,19 @@ public class Mahjongg : 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-mahjongg", VERSION);
+ return Posix.EXIT_SUCCESS;
+ }
+
+ /* Activate */
+ return -1;
+ }
+
public override void activate ()
{
window.present ();
@@ -789,27 +810,11 @@ public class Mahjongg : Gtk.Application
Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (GETTEXT_PACKAGE);
- Gtk.init (ref args);
-
- 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)
- {
- stdout.printf ("%s\n", e.message);
- return Posix.EXIT_FAILURE;
- }
-
Environment.set_application_name (_("Mahjongg"));
Gtk.Window.set_default_icon_name ("gnome-mahjongg");
var app = new Mahjongg ();
- var result = app.run ();
+ var result = app.run (args);
Settings.sync();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]