[PATCH 1/3] cli: add support for parsing multiple keyword arguments
Jani Nikula
jani at nikula.org
Sat Sep 6 05:53:28 PDT 2014
This allows having multiple --foo=bar --foo=baz options on the command
line, with the corresponding values OR'd together.
---
command-line-arguments.c | 6 +++++-
command-line-arguments.h | 1 +
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/command-line-arguments.c b/command-line-arguments.c
index 844d6c3d18bf..c6f7269603cb 100644
--- a/command-line-arguments.c
+++ b/command-line-arguments.c
@@ -23,7 +23,10 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char
while (keywords->name) {
if (strcmp (arg_str, keywords->name) == 0) {
if (arg_desc->output_var) {
- *((int *)arg_desc->output_var) = keywords->value;
+ if (arg_desc->opt_type == NOTMUCH_OPT_KEYWORD_FLAGS)
+ *((int *)arg_desc->output_var) |= keywords->value;
+ else
+ *((int *)arg_desc->output_var) = keywords->value;
}
return TRUE;
}
@@ -152,6 +155,7 @@ parse_option (const char *arg,
switch (try->opt_type) {
case NOTMUCH_OPT_KEYWORD:
+ case NOTMUCH_OPT_KEYWORD_FLAGS:
return _process_keyword_arg (try, next, value);
case NOTMUCH_OPT_BOOLEAN:
return _process_boolean_arg (try, next, value);
diff --git a/command-line-arguments.h b/command-line-arguments.h
index de1734ad2fdb..085a4923b5fa 100644
--- a/command-line-arguments.h
+++ b/command-line-arguments.h
@@ -8,6 +8,7 @@ enum notmuch_opt_type {
NOTMUCH_OPT_BOOLEAN, /* --verbose */
NOTMUCH_OPT_INT, /* --frob=8 */
NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */
+ NOTMUCH_OPT_KEYWORD_FLAGS, /* the above with values OR'd together */
NOTMUCH_OPT_STRING, /* --file=/tmp/gnarf.txt */
NOTMUCH_OPT_POSITION /* notmuch dump pos_arg */
};
--
2.1.0
More information about the notmuch
mailing list