[gnome-tetravex] Fix command-line on bad arg.



commit 7c8f82ecd7ed55a7648c652497af508b8074de01
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Nov 5 21:54:52 2019 +0100

    Fix command-line on bad arg.

 src/gnome-tetravex.vala | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index b80c65b..4534f00 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -64,28 +64,31 @@ private class Tetravex : Gtk.Application
 
     private MenuButton hamburger_button;
 
+    private static string? [] remaining = new string? [1];
     private const OptionEntry [] option_entries =
     {
         /* Translators: command-line option description, see 'gnome-tetravex --help' */
-        { "colors",  'c', OptionFlags.NONE, OptionArg.INT,  ref colors,    N_("Set number of colors (2-10)"),
+        { "colors",  'c', OptionFlags.NONE, OptionArg.INT,  ref colors,                 N_("Set number of 
colors (2-10)"),
 
         /* Translators: in the command-line options description, text to indicate the user should specify 
colors number, see 'gnome-tetravex --help' */
-                                                                           N_("NUMBER") },
+                                                                                        N_("NUMBER") },
 
         /* Translators: command-line option description, see 'gnome-tetravex --help' */
-        { "paused",  'p', OptionFlags.NONE, OptionArg.NONE, null,          N_("Start the game paused"),      
    null },
+        { "paused",  'p', OptionFlags.NONE, OptionArg.NONE, null,                       N_("Start the game 
paused"),            null },
 
         /* Translators: command-line option description, see 'gnome-tetravex --help' */
-        { "restore", 'r', OptionFlags.NONE, OptionArg.NONE, null,          N_("Restore last game, if any"),  
    null },
+        { "restore", 'r', OptionFlags.NONE, OptionArg.NONE, null,                       N_("Restore last 
game, if any"),        null },
 
         /* Translators: command-line option description, see 'gnome-tetravex --help' */
-        { "size",    's', OptionFlags.NONE, OptionArg.INT,  ref game_size, N_("Set size of board (2-6)"),
+        { "size",    's', OptionFlags.NONE, OptionArg.INT,  ref game_size,              N_("Set size of 
board (2-6)"),
 
         /* Translators: in the command-line options description, text to indicate the user should specify 
size, see 'gnome-tetravex --help' */
-                                                                           N_("SIZE") },
+                                                                                        N_("SIZE") },
 
         /* Translators: command-line option description, see 'gnome-tetravex --help' */
-        { "version", 'v', OptionFlags.NONE, OptionArg.NONE, null,          N_("Print release version and 
exit"), null },
+        { "version", 'v', OptionFlags.NONE, OptionArg.NONE, null,                       N_("Print release 
version and exit"),   null },
+
+        { OPTION_REMAINING, 0, OptionFlags.NONE, OptionArg.STRING_ARRAY, ref remaining, "args", null },
         {}
     };
 
@@ -132,7 +135,8 @@ private class Tetravex : Gtk.Application
 
     protected override int handle_local_options (GLib.VariantDict options)
     {
-        if (options.contains ("version"))
+        if (options.contains ("version")
+         || remaining [0] != null && (!) remaining [0] == "version")
         {
             /* NOTE: Is not translated so can be easily parsed */
             stderr.printf ("%1$s %2$s\n", "gnome-tetravex", VERSION);
@@ -159,6 +163,13 @@ private class Tetravex : Gtk.Application
             return Posix.EXIT_FAILURE;
         }
 
+        if (remaining [0] != null)
+        {
+            /* Translators: command-line error message, displayed for an invalid CLI command; see 
'gnome-tetravex cli' */
+            stderr.printf (N_("Failed to parse command-line arguments.\n"));
+            return Posix.EXIT_FAILURE;
+        }
+
         /* Activate */
         return -1;
     }


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