mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-12 20:24:04 +02:00
Return an error if an option is missing its argument. (#305576, Björn
2005-05-27 Matthias Clasen <mclasen@redhat.com> * glib/goption.c (parse_short_option, parse_long_option): Return an error if an option is missing its argument. (#305576, Björn Lindqvist) * tests/option-test.c (missing_arg_test): Add a testcase.
This commit is contained in:
committed by
Matthias Clasen
parent
8db223409d
commit
4c4f106344
@@ -1,3 +1,11 @@
|
|||||||
|
2005-05-27 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* glib/goption.c (parse_short_option, parse_long_option):
|
||||||
|
Return an error if an option is missing its argument. (#305576,
|
||||||
|
Björn Lindqvist)
|
||||||
|
|
||||||
|
* tests/option-test.c (missing_arg_test): Add a testcase.
|
||||||
|
|
||||||
Wed May 25 15:33:51 2005 Manish Singh <yosh@gimp.org>
|
Wed May 25 15:33:51 2005 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib/goption.c (print_help): rest_description should be const.
|
* glib/goption.c (print_help): rest_description should be const.
|
||||||
|
@@ -1,3 +1,11 @@
|
|||||||
|
2005-05-27 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* glib/goption.c (parse_short_option, parse_long_option):
|
||||||
|
Return an error if an option is missing its argument. (#305576,
|
||||||
|
Björn Lindqvist)
|
||||||
|
|
||||||
|
* tests/option-test.c (missing_arg_test): Add a testcase.
|
||||||
|
|
||||||
Wed May 25 15:33:51 2005 Manish Singh <yosh@gimp.org>
|
Wed May 25 15:33:51 2005 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib/goption.c (print_help): rest_description should be const.
|
* glib/goption.c (print_help): rest_description should be const.
|
||||||
|
@@ -1,3 +1,11 @@
|
|||||||
|
2005-05-27 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* glib/goption.c (parse_short_option, parse_long_option):
|
||||||
|
Return an error if an option is missing its argument. (#305576,
|
||||||
|
Björn Lindqvist)
|
||||||
|
|
||||||
|
* tests/option-test.c (missing_arg_test): Add a testcase.
|
||||||
|
|
||||||
Wed May 25 15:33:51 2005 Manish Singh <yosh@gimp.org>
|
Wed May 25 15:33:51 2005 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib/goption.c (print_help): rest_description should be const.
|
* glib/goption.c (print_help): rest_description should be const.
|
||||||
|
@@ -1,3 +1,11 @@
|
|||||||
|
2005-05-27 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* glib/goption.c (parse_short_option, parse_long_option):
|
||||||
|
Return an error if an option is missing its argument. (#305576,
|
||||||
|
Björn Lindqvist)
|
||||||
|
|
||||||
|
* tests/option-test.c (missing_arg_test): Add a testcase.
|
||||||
|
|
||||||
Wed May 25 15:33:51 2005 Manish Singh <yosh@gimp.org>
|
Wed May 25 15:33:51 2005 Manish Singh <yosh@gimp.org>
|
||||||
|
|
||||||
* glib/goption.c (print_help): rest_description should be const.
|
* glib/goption.c (print_help): rest_description should be const.
|
||||||
|
@@ -907,8 +907,13 @@ parse_short_option (GOptionContext *context,
|
|||||||
*new_index = index + 1;
|
*new_index = index + 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
value = "";
|
{
|
||||||
|
g_set_error (error,
|
||||||
|
G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
|
||||||
|
_("Missing argument for %s"), option_name);
|
||||||
|
g_free (option_name);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
option_name = g_strdup_printf ("-%c", group->entries[j].short_name);
|
option_name = g_strdup_printf ("-%c", group->entries[j].short_name);
|
||||||
|
|
||||||
@@ -964,6 +969,7 @@ parse_long_option (GOptionContext *context,
|
|||||||
gchar *option_name;
|
gchar *option_name;
|
||||||
|
|
||||||
add_pending_null (context, &((*argv)[*index]), NULL);
|
add_pending_null (context, &((*argv)[*index]), NULL);
|
||||||
|
option_name = g_strconcat ("--", group->entries[j].long_name, NULL);
|
||||||
|
|
||||||
if (arg[len] == '=')
|
if (arg[len] == '=')
|
||||||
value = arg + len + 1;
|
value = arg + len + 1;
|
||||||
@@ -974,9 +980,13 @@ parse_long_option (GOptionContext *context,
|
|||||||
(*index)++;
|
(*index)++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
value = "";
|
{
|
||||||
|
g_set_error (error,
|
||||||
option_name = g_strconcat ("--", group->entries[j].long_name, NULL);
|
G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
|
||||||
|
_("Missing argument for %s"), option_name);
|
||||||
|
g_free (option_name);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (!parse_arg (context, group, &group->entries[j], value, option_name, error))
|
if (!parse_arg (context, group, &group->entries[j], value, option_name, error))
|
||||||
{
|
{
|
||||||
|
@@ -883,6 +883,41 @@ void lonely_dash_test (void)
|
|||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
missing_arg_test (void)
|
||||||
|
{
|
||||||
|
GOptionContext *context;
|
||||||
|
gboolean retval;
|
||||||
|
GError *error = NULL;
|
||||||
|
gchar **argv;
|
||||||
|
int argc;
|
||||||
|
gchar *arg = NULL;
|
||||||
|
GOptionEntry entries [] =
|
||||||
|
{ { "test", 't', 0, G_OPTION_ARG_STRING, &arg, NULL, NULL },
|
||||||
|
{ NULL } };
|
||||||
|
|
||||||
|
context = g_option_context_new (NULL);
|
||||||
|
g_option_context_add_main_entries (context, entries, NULL);
|
||||||
|
|
||||||
|
/* Now try parsing */
|
||||||
|
argv = split_string ("program --test", &argc);
|
||||||
|
|
||||||
|
retval = g_option_context_parse (context, &argc, &argv, &error);
|
||||||
|
g_assert (retval == FALSE);
|
||||||
|
g_clear_error (&error);
|
||||||
|
|
||||||
|
g_strfreev (argv);
|
||||||
|
|
||||||
|
/* Try parsing again */
|
||||||
|
argv = split_string ("program --t", &argc);
|
||||||
|
|
||||||
|
retval = g_option_context_parse (context, &argc, &argv, &error);
|
||||||
|
g_assert (retval == FALSE);
|
||||||
|
|
||||||
|
g_strfreev (argv);
|
||||||
|
g_option_context_free (context);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@@ -931,5 +966,8 @@ main (int argc, char **argv)
|
|||||||
/* test for bug 168008 */
|
/* test for bug 168008 */
|
||||||
lonely_dash_test ();
|
lonely_dash_test ();
|
||||||
|
|
||||||
|
/* test for bug 305576 */
|
||||||
|
missing_arg_test ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user