shared/options: add a 'data' parameter to options

This mirrors a similar field in Verb. In some cases it convenient
to pass a fixed value to the parser.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-04-23 11:13:07 +02:00
parent 9a3a861ff8
commit 8cb4ff428e
2 changed files with 20 additions and 3 deletions
+12
View File
@@ -772,6 +772,12 @@ static void test_macros_parse_one(
if (entries[i].short_code != 0)
ASSERT_EQ(opt->short_code, entries[i].short_code);
ASSERT_TRUE(streq_ptr(arg, entries[i].argument));
if (streq_ptr(entries[i].long_code, "optional2"))
ASSERT_EQ(opt->data, 666u);
else
ASSERT_EQ(opt->data, 0u);
i++;
switch (c) {
@@ -796,6 +802,10 @@ static void test_macros_parse_one(
OPTION_FULL(OPTION_OPTIONAL_ARG, 'o', "optional", "ARG", "Optional arg option"):
break;
/* OPTION_FULL_DATA: optional arg */
OPTION_FULL_DATA(OPTION_OPTIONAL_ARG, 'O', "optional2", "ARG", 666, "Optional arg option"):
break;
/* OPTION_FULL: stops parsing */
OPTION_FULL(OPTION_STOPS_PARSING, 0, "exec", NULL, "Stop parsing after this"):
break;
@@ -1015,6 +1025,7 @@ TEST(option_macros) {
"-v",
"--required=rval",
"--optional=oval",
"--optional2=oval",
"--debug",
"pos2",
"-o",
@@ -1025,6 +1036,7 @@ TEST(option_macros) {
{ .short_code = 'v' },
{ "required", "rval" },
{ "optional", "oval" },
{ "optional2", "oval" },
{ "debug" },
{ "optional", NULL },
{ "help" },