From 3e3fe296e5c5bda7a6376428616b50515ad4a93c Mon Sep 17 00:00:00 2001 From: Marek Kasik Date: Tue, 9 Apr 2013 18:03:53 +0200 Subject: [PATCH] Don't show help options when help is disabled Check whether help is enabled when creating help text in g_option_context_get_help(). https://bugzilla.gnome.org/show_bug.cgi?id=697652 --- glib/goption.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/glib/goption.c b/glib/goption.c index e33f992..0a22f6f 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -723,7 +723,7 @@ g_option_context_get_help (GOptionContext *context, GOptionGroup *group) { GList *list; - gint max_length, len; + gint max_length = 0, len; gint i; GOptionEntry *entry; GHashTable *shadow_map; @@ -822,12 +822,15 @@ g_option_context_get_help (GOptionContext *context, list = context->groups; - max_length = _g_utf8_strwidth ("-?, --help"); - - if (list) + if (context->help_enabled) { - len = _g_utf8_strwidth ("--help-all"); - max_length = MAX (max_length, len); + max_length = _g_utf8_strwidth ("-?, --help"); + + if (list) + { + len = _g_utf8_strwidth ("--help-all"); + max_length = MAX (max_length, len); + } } if (context->main_group) @@ -840,9 +843,12 @@ g_option_context_get_help (GOptionContext *context, { GOptionGroup *g = list->data; - /* First, we check the --help- options */ - len = _g_utf8_strwidth ("--help-") + _g_utf8_strwidth (g->name); - max_length = MAX (max_length, len); + if (context->help_enabled) + { + /* First, we check the --help- options */ + len = _g_utf8_strwidth ("--help-") + _g_utf8_strwidth (g->name); + max_length = MAX (max_length, len); + } /* Then we go through the entries */ len = calculate_max_length (g, aliases); @@ -854,7 +860,7 @@ g_option_context_get_help (GOptionContext *context, /* Add a bit of padding */ max_length += 4; - if (!group) + if (!group && context->help_enabled) { list = context->groups; -- 2.7.4