[ghex] cmdline: Add --version option.



commit ea7d2a8c35d121d59b271cd0a3b037eb10f37324
Author: Logan Rathbone <poprocks gmail com>
Date:   Fri Dec 10 22:51:16 2021 -0500

    cmdline: Add --version option.
    
    Fixes #5

 src/main.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
---
diff --git a/src/main.c b/src/main.c
index ff41af0..8efb42a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,6 +36,16 @@
 
 #include <config.h>
 
+GOptionEntry entries[] = {
+       {       .long_name =    "version",
+               .short_name =   'v',
+               .flags =                G_OPTION_FLAG_NONE,
+               .arg =                  G_OPTION_ARG_NONE,
+               .description =  N_("Show the application version"),
+       },
+       { NULL }
+};
+
 static GtkWindow *window = NULL;
 
 /* FIXME - TEST ON WIN32.
@@ -85,6 +95,20 @@ do_app_window (GtkApplication *app)
                                (GHEX_APPLICATION_WINDOW(window)));
 }
 
+static int
+handle_local_options (GApplication *application,
+               GVariantDict *options,
+               gpointer      user_data)
+{
+       if (g_variant_dict_contains (options, "version"))
+       {
+               g_print (_("This is GHex, version %s\n"), PACKAGE_VERSION);
+
+               return 0;       /* exit successfully (see TFM) */
+       }
+       return -1;              /* let processing continue (see TFM) */
+}
+
 static void
 activate (GtkApplication *app,
        gpointer user_data)
@@ -135,8 +159,15 @@ main (int argc, char *argv[])
 
        app = gtk_application_new (APP_ID, G_APPLICATION_HANDLES_OPEN);
 
+       g_application_add_main_option_entries (G_APPLICATION(app), entries);
+
+       g_application_set_option_context_summary (G_APPLICATION(app),
+                       _("GHex - A hex editor for the GNOME desktop"));;
+
        g_signal_connect (app, "activate", G_CALLBACK(activate), NULL);
        g_signal_connect (app, "open", G_CALLBACK(open), NULL);
+       g_signal_connect (app, "handle-local-options",
+                       G_CALLBACK(handle_local_options), NULL);
 
        g_application_register (G_APPLICATION (app), NULL, NULL);
 


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