+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.
+
2008-01-23 Jens Granseuer <jensgr@gmx.net>
* glib/gtestutils.c: (g_test_trap_fork):
}
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;
{
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;
}
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;
{
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));
{
/* 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");
{
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");
/* 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;
*/
#include <glib/gtestutils.h>
+#include <stdlib.h>
+
static void
group_captions (void)
{
GOptionEntry main_entries[] = {
{ "main-switch", 0,
- G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_IN_MAIN,
+ G_OPTION_FLAG_NO_ARG,
G_OPTION_ARG_NONE, NULL,
"A switch that is in the main group", NULL },
{ NULL }
gboolean have_test_entries = (0 != (i & 2));
GOptionContext *options;
- GOptionGroup *group;
+ GOptionGroup *group = NULL;
options = g_option_context_new (NULL);
- group = g_option_group_new ("test", "Test Options",
- "Show all test options",
- NULL, NULL);
if (have_main_entries)
g_option_context_add_main_entries (options, main_entries, NULL);
if (have_test_entries)
- g_option_group_add_entries (group, group_entries);
-
- g_option_context_add_group (options, group);
+ {
+ group = g_option_group_new ("test", "Test Options",
+ "Show all test options",
+ NULL, NULL);
+ g_option_context_add_group (options, group);
+ g_option_group_add_entries (group, group_entries);
+ }
for (j = 0; j < G_N_ELEMENTS (help_variants); ++j)
{
{
gchar **argv = args;
gint argc = 2;
+ GError *error = NULL;
- g_option_context_parse (options, &argc, &argv, NULL);
- g_assert_not_reached ();
+ g_option_context_parse (options, &argc, &argv, &error);
+ exit(0);
}
else
{