[gnome-text-editor] main: add --version command line argument



commit d9d2e3ab2f0a028ffea5a7ddb06c003c76b6d71b
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jun 19 15:47:57 2022 -0700

    main: add --version command line argument

 src/editor-application.c |  1 +
 src/main.c               | 23 +++++++++++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/src/editor-application.c b/src/editor-application.c
index a89ff86..129136f 100644
--- a/src/editor-application.c
+++ b/src/editor-application.c
@@ -662,6 +662,7 @@ static const GOptionEntry entries[] = {
   { "ignore-session", 'i', 0, G_OPTION_ARG_NONE, NULL, N_("Do not restore session at startup") },
   { "new-window", 'n', 0, G_OPTION_ARG_NONE, NULL, N_("Open provided files in a new window") },
   { "standalone", 's', 0, G_OPTION_ARG_NONE, NULL, N_("Run a new instance of Text Editor (implies 
--ignore-session)") },
+  { "version", 0, 0, G_OPTION_ARG_NONE, NULL, N_("Print version information and exit") },
   { 0 }
 };
 
diff --git a/src/main.c b/src/main.c
index c0ad6fc..65bbe97 100644
--- a/src/main.c
+++ b/src/main.c
@@ -22,16 +22,19 @@
 
 #include <glib/gi18n.h>
 
+#include "build-ident.h"
 #include "editor-application-private.h"
 
-static gboolean
-check_standalone (int    *argc,
-                  char ***argv)
+static void
+check_early_opts (int        *argc,
+                  char     ***argv,
+                  gboolean   *standalone)
 {
   g_autoptr(GOptionContext) context = NULL;
-  gboolean standalone = FALSE;
+  gboolean version = FALSE;
   GOptionEntry entries[] = {
-    { "standalone", 's', 0, G_OPTION_ARG_NONE, &standalone },
+    { "standalone", 's', 0, G_OPTION_ARG_NONE, standalone },
+    { "version", 0, 0, G_OPTION_ARG_NONE, &version },
     { NULL }
   };
 
@@ -41,7 +44,11 @@ check_standalone (int    *argc,
   g_option_context_add_main_entries (context, entries, NULL);
   g_option_context_parse (context, argc, argv, NULL);
 
-  return standalone;
+  if (version)
+    {
+      g_printerr ("%s %s (%s)\n", PACKAGE_NAME, PACKAGE_VERSION, EDITOR_BUILD_IDENTIFIER);
+      exit (EXIT_SUCCESS);
+    }
 }
 
 int
@@ -49,14 +56,14 @@ main (int   argc,
       char *argv[])
 {
   g_autoptr(EditorApplication) app = NULL;
-  gboolean standalone;
+  gboolean standalone = FALSE;
   int ret;
 
   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   textdomain (GETTEXT_PACKAGE);
 
-  standalone = check_standalone (&argc, &argv);
+  check_early_opts (&argc, &argv, &standalone);
 
   gtk_init ();
   gtk_source_init ();


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