From: Jani Nikula Date: Sun, 1 Oct 2017 20:53:14 +0000 (+0300) Subject: cli: add .present field to opt desc to check if the arg was present X-Git-Tag: 0.26_rc0~125 X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=bc99087ff95d0cdada827f3b838d05e0c9448b63;p=notmuch cli: add .present field to opt desc to check if the arg was present Add pointer to boolean .present field to opt desc, which (if non-NULL) will be set to TRUE if the argument in question is present on the command line. Unchanged otherwise. --- diff --git a/command-line-arguments.c b/command-line-arguments.c index f1a5b232..39940d5f 100644 --- a/command-line-arguments.c +++ b/command-line-arguments.c @@ -128,6 +128,8 @@ parse_position_arg (const char *arg_str, int pos_arg_index, if (arg_desc->opt_position) { if (pos_arg_counter == pos_arg_index) { *arg_desc->opt_position = arg_str; + if (arg_desc->present) + *arg_desc->present = TRUE; return TRUE; } pos_arg_counter++; @@ -202,10 +204,13 @@ parse_option (int argc, char **argv, const notmuch_opt_desc_t *options, int opt_ else INTERNAL_ERROR ("unknown or unhandled option \"%s\"", try->name); - if (opt_status) - return opt_index+1; - else + if (! opt_status) return -1; + + if (try->present) + *try->present = TRUE; + + return opt_index+1; } return -1; } diff --git a/command-line-arguments.h b/command-line-arguments.h index ff51abce..dfc808bd 100644 --- a/command-line-arguments.h +++ b/command-line-arguments.h @@ -27,6 +27,9 @@ typedef struct notmuch_opt_desc { /* Must be set except for opt_inherit and opt_position. */ const char *name; + /* Optional, if non-NULL, set to TRUE if the option is present. */ + notmuch_bool_t *present; + /* Must be set for opt_keyword and opt_flags. */ const struct notmuch_keyword *keywords; } notmuch_opt_desc_t;