mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-24 03:48:10 +01:00
cli: add support for hierarchical command line option arrays
NOTMUCH_OPT_INHERIT expects a notmuch_opt_desc_t * pointer in output_var. The "Unrecognized option" message was moved out of parse_option() to not be emitted twice or when parsing a non-inherited option.
This commit is contained in:
parent
f0dfceaf90
commit
4387112de0
2 changed files with 10 additions and 7 deletions
|
@ -122,16 +122,18 @@ parse_position_arg (const char *arg_str, int pos_arg_index,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
notmuch_bool_t
|
notmuch_bool_t
|
||||||
parse_option (const char *arg,
|
parse_option (const char *_arg, const notmuch_opt_desc_t *options)
|
||||||
const notmuch_opt_desc_t *options) {
|
{
|
||||||
|
assert(_arg);
|
||||||
assert(arg);
|
|
||||||
assert(options);
|
assert(options);
|
||||||
|
|
||||||
arg += 2;
|
const char *arg = _arg + 2; /* _arg starts with -- */
|
||||||
|
|
||||||
const notmuch_opt_desc_t *try;
|
const notmuch_opt_desc_t *try;
|
||||||
for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) {
|
for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) {
|
||||||
|
if (try->opt_type == NOTMUCH_OPT_INHERIT &&
|
||||||
|
parse_option (_arg, try->output_var))
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
if (! try->name)
|
if (! try->name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -170,7 +172,6 @@ parse_option (const char *arg,
|
||||||
/*UNREACHED*/
|
/*UNREACHED*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf (stderr, "Unrecognized option: --%s\n", arg);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,6 +202,7 @@ parse_arguments (int argc, char **argv,
|
||||||
if (more_args) {
|
if (more_args) {
|
||||||
opt_index++;
|
opt_index++;
|
||||||
} else {
|
} else {
|
||||||
|
fprintf (stderr, "Unrecognized option: %s\n", argv[opt_index]);
|
||||||
opt_index = -1;
|
opt_index = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
enum notmuch_opt_type {
|
enum notmuch_opt_type {
|
||||||
NOTMUCH_OPT_END = 0,
|
NOTMUCH_OPT_END = 0,
|
||||||
|
NOTMUCH_OPT_INHERIT, /* another options table */
|
||||||
NOTMUCH_OPT_BOOLEAN, /* --verbose */
|
NOTMUCH_OPT_BOOLEAN, /* --verbose */
|
||||||
NOTMUCH_OPT_INT, /* --frob=8 */
|
NOTMUCH_OPT_INT, /* --frob=8 */
|
||||||
NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */
|
NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */
|
||||||
|
|
Loading…
Reference in a new issue