diff options
author | Loïc Minier <lool@dooz.org> | 2008-01-25 17:49:53 +0000 |
---|---|---|
committer | Loic Minier <lminier@src.gnome.org> | 2008-01-25 17:49:53 +0000 |
commit | 64c2dc4a06861f360c80691357dbf2692c528838 (patch) | |
tree | 1972f9a28b30e887340d90065682a4309d047838 /glib/goption.c | |
parent | 1f331ffde8812d016c7524f27fd72cc72c7aa21d (diff) | |
download | glib-64c2dc4a06861f360c80691357dbf2692c528838.tar.gz |
Pass context down the implementation to check for the main_group. Bug
2008-01-25 Loïc Minier <lool@dooz.org>
* glib/goption.c: (group_has_visible_entries),
(group_list_has_visible_entires), (g_option_context_get_help): Pass
context down the implementation to check for the main_group.
Bug #510292.
* glib/tests/option-context.c:
Don't set G_OPTION_FLAG_IN_MAIN in main_entries
(group_captions): only create group when actually adding it to the
context; add an exit(0) to make sure the test succeeds.
svn path=/trunk/; revision=6377
Diffstat (limited to 'glib/goption.c')
-rw-r--r-- | glib/goption.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/glib/goption.c b/glib/goption.c index c659f841a..6b498271c 100644 --- a/glib/goption.c +++ b/glib/goption.c @@ -521,12 +521,14 @@ print_entry (GOptionGroup *group, } static gboolean -group_has_visible_entries (GOptionGroup *group, +group_has_visible_entries (GOptionContext *context, + GOptionGroup *group, gboolean main_entries) { GOptionFlags reject_filter = G_OPTION_FLAG_HIDDEN; GOptionEntry *entry; gint i, l; + gboolean main_group = group == context->main_group; if (!main_entries) reject_filter |= G_OPTION_FLAG_IN_MAIN; @@ -535,7 +537,7 @@ group_has_visible_entries (GOptionGroup *group, { entry = &group->entries[i]; - if (main_entries && !(entry->flags & G_OPTION_FLAG_IN_MAIN)) + if (main_entries && !main_group && !(entry->flags & G_OPTION_FLAG_IN_MAIN)) continue; if (!(entry->flags & reject_filter)) return TRUE; @@ -545,12 +547,14 @@ group_has_visible_entries (GOptionGroup *group, } static gboolean -group_list_has_visible_entires (GList *group_list, - gboolean main_entries) +group_list_has_visible_entires (GOptionContext *context, + GList *group_list, + gboolean main_entries) { while (group_list) { - if (group_has_visible_entries (group_list->data, main_entries)) + gboolean is_main_group = context->main_group == group_list->data; + if (group_has_visible_entries (context, group_list->data, main_entries)) return TRUE; group_list = group_list->next; @@ -726,7 +730,7 @@ g_option_context_get_help (GOptionContext *context, { GOptionGroup *group = list->data; - if (group_has_visible_entries (group, FALSE)) + if (group_has_visible_entries (context, group, FALSE)) g_string_append_printf (string, " --help-%-*s %s\n", max_length - 5, group->name, TRANSLATE (group, group->help_description)); @@ -741,7 +745,7 @@ g_option_context_get_help (GOptionContext *context, { /* Print a certain group */ - if (group_has_visible_entries (group, FALSE)) + if (group_has_visible_entries (context, group, FALSE)) { g_string_append (string, TRANSLATE (group, group->description)); g_string_append (string, "\n"); @@ -760,7 +764,7 @@ g_option_context_get_help (GOptionContext *context, { GOptionGroup *group = list->data; - if (group_has_visible_entries (group, FALSE)) + if (group_has_visible_entries (context, group, FALSE)) { g_string_append (string, group->description); g_string_append (string, "\n"); @@ -777,8 +781,8 @@ g_option_context_get_help (GOptionContext *context, /* Print application options if --help or --help-all has been specified */ if ((main_help || !group) && - (group_has_visible_entries (context->main_group, TRUE) || - group_list_has_visible_entires (context->groups, TRUE))) + (group_has_visible_entries (context, context->main_group, TRUE) || + group_list_has_visible_entires (context, context->groups, TRUE))) { list = context->groups; |