[gjs] console: improve --help handling



commit 9428ef45bbf60d909d858078ad55e510b7c29a89
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Wed Sep 25 16:24:10 2013 +0200

    console: improve --help handling
    
    Only recognize -h/--help if it's the first argument that is not
    eaten by GOptionContext. This way it's possible to interpret
    --help after the filename as application help, rather than gjs help.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=708831

 gjs/console.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/gjs/console.c b/gjs/console.c
index 41c592b..4593d7e 100644
--- a/gjs/console.c
+++ b/gjs/console.c
@@ -39,6 +39,20 @@ static GOptionEntry entries[] = {
     { NULL }
 };
 
+G_GNUC_NORETURN
+static void
+print_help (GOptionContext *context,
+            gboolean        main_help)
+{
+  gchar *help;
+
+  help = g_option_context_get_help (context, main_help, NULL);
+  g_print ("%s", help);
+  g_free (help);
+
+  exit (0);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -57,11 +71,19 @@ main(int argc, char **argv)
 
     /* pass unknown through to the JS script */
     g_option_context_set_ignore_unknown_options(context, TRUE);
+    g_option_context_set_help_enabled(context, FALSE);
 
     g_option_context_add_main_entries(context, entries, NULL);
     if (!g_option_context_parse(context, &argc, &argv, &error))
         g_error("option parsing failed: %s", error->message);
 
+    if (argc >= 2) {
+        if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)
+            print_help(context, TRUE);
+        else if (strcmp(argv[1], "--help-all") == 0)
+            print_help(context, FALSE);
+    }
+
     g_option_context_free (context);
 
     setlocale(LC_ALL, "");


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