diff --git a/readarg.h b/readarg.h index 9c70386..52dd00e 100644 --- a/readarg.h +++ b/readarg.h @@ -45,9 +45,6 @@ struct readarg_opt { /* Two null-terminated arrays of either long or short option names. */ char **names[2]; - - int req; - struct readarg_arg arg; }; @@ -249,7 +246,7 @@ static void readarg_parse_opt(struct readarg_parser *rp, enum readarg_form form, { const char *strpos = *pos; - if (!match->req && *strpos) + if (!match->arg.name && *strpos) { rp->state.grppos = strpos; readarg_update_opt(rp, NULL, match); @@ -348,7 +345,7 @@ static struct readarg_opt *readarg_match_finish(struct readarg_parser *rp, const static void readarg_update_opt(struct readarg_parser *rp, const char *attach, struct readarg_opt *opt) { - if (opt->req) + if (opt->arg.name) { if (attach) { @@ -630,17 +627,10 @@ int readarg_helpgen_put_usage(struct readarg_parser *rp, struct readarg_helpgen_ { READARG_HELPGEN_TRY_LIT(writer, ", "); } - else if (opts[i].req) + else if (opts[i].arg.name) { READARG_HELPGEN_TRY_LIT(writer, " "); - if (opts[i].arg.name) - { - READARG_HELPGEN_TRY_STR(writer, opts[i].arg.name); - } - else - { - READARG_HELPGEN_TRY_LIT(writer, "value"); - } + READARG_HELPGEN_TRY_STR(writer, opts[i].arg.name); if (inf) { diff --git a/test/test.c b/test/test.c index 5925c85..463c3b9 100644 --- a/test/test.c +++ b/test/test.c @@ -38,40 +38,45 @@ int main(int argc, char **argv) [READARG_FORM_SHORT] = READARG_STRINGS("e", "x"), [READARG_FORM_LONG] = READARG_STRINGS("expr", "expression"), }, - .req = 1, - .arg.bounds.val = { - 1, - 4, - }, + .arg = { + .name = "expression", + .bounds.val = { + 1, + 4, + }, + } }, { .names = { [READARG_FORM_SHORT] = READARG_STRINGS("c"), [READARG_FORM_LONG] = READARG_STRINGS("config"), }, - .req = 1, .arg = { .name = "file", .bounds.val = { 2, }, - }, + } }, { .names = { [READARG_FORM_SHORT] = READARG_STRINGS("i"), [READARG_FORM_LONG] = READARG_STRINGS("uri"), }, - .req = 1, - .arg.bounds.inf = 1, + .arg = { + .name = "uri", + .bounds.inf = 1, + } }, { .names = { [READARG_FORM_SHORT] = READARG_STRINGS("b"), [READARG_FORM_LONG] = READARG_STRINGS("backup", "backup-file"), }, - .req = 1, - .arg.bounds.inf = 1, + .arg = { + .name = "file", + .bounds.inf = 1, + } }, { .names = { @@ -178,7 +183,7 @@ int main(int argc, char **argv) } } printf("{ [%zu] ", curr[i].arg.val.len); - if (curr[i].req) + if (curr[i].arg.name) { struct readarg_view_strings val = curr[i].arg.val; for (size_t j = 0; j < val.len; j++)