mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 02:06:18 +01:00
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
This commit is contained in:
parent
1f331ffde8
commit
64c2dc4a06
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
||||
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):
|
||||
|
@ -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,
|
||||
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;
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
*/
|
||||
#include <glib/gtestutils.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static void
|
||||
group_captions (void)
|
||||
{
|
||||
@ -28,7 +30,7 @@ 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 }
|
||||
@ -52,19 +54,20 @@ group_captions (void)
|
||||
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);
|
||||
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -78,9 +81,10 @@ group_captions (void)
|
||||
{
|
||||
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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user