[swell-foop/arnaudb/add---version: 1/6] Add --version command-line option.



commit 43a42a48ec714c9cc2802ff9a478d8d3e29801de
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu May 14 11:42:57 2020 +0200

    Add --version command-line option.

 src/swell-foop.vala | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
---
diff --git a/src/swell-foop.vala b/src/swell-foop.vala
index 772e7d5..36a8e92 100644
--- a/src/swell-foop.vala
+++ b/src/swell-foop.vala
@@ -18,6 +18,17 @@ public class SwellFoop : Gtk.Application
     /* Main window */
     private SwellFoopWindow window;
 
+    /* Command-line options */
+    private static bool version = false;
+    private const OptionEntry [] option_entries =
+    {
+        /* Translators: command-line option description, see 'swell-foop --help' */
+        { "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, N_("Print release version and 
exit"), null },
+
+        {}
+    };
+
+    /* Actions */
     private const GLib.ActionEntry[] action_entries =
     {
         { "help",          help_cb        },
@@ -132,6 +143,8 @@ public class SwellFoop : Gtk.Application
         context.add_group (Gtk.get_option_group (true));
         context.add_group (Clutter.get_option_group_without_init ());
 
+        context.add_main_entries (option_entries, Config.GETTEXT_PACKAGE);
+
         try
         {
             context.parse (ref args);
@@ -142,6 +155,13 @@ public class SwellFoop : Gtk.Application
             return Posix.EXIT_FAILURE;
         }
 
+        if (version)
+        {
+            /* NOTE: Is not translated so can be easily parsed */
+            stderr.printf ("%1$s %2$s\n", "swell-foop", Config.VERSION);
+            return Posix.EXIT_SUCCESS;
+        }
+
         /* Translators: name of the application, as displayed in the window manager */
         Environment.set_application_name (_("Swell Foop"));
         Gtk.Window.set_default_icon_name ("org.gnome.SwellFoop");


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