--- /dev/null
+Return-Path: <sojkam1@fel.cvut.cz>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1BF45429E26\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 16:59:53 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id uECF9UtwyQqN for <notmuch@notmuchmail.org>;\r
+ Thu, 30 Oct 2014 16:59:45 -0700 (PDT)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+ by olra.theworths.org (Postfix) with ESMTP id 0727B431FCB\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 16:59:45 -0700 (PDT)\r
+Received: from localhost (unknown [192.168.200.7])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id 64D965CCFF4;\r
+ Fri, 31 Oct 2014 00:59:44 +0100 (CET)\r
+X-Virus-Scanned: IMAP STYX AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+ by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
+ port 10044)\r
+ with ESMTP id 7YAN5TwX4NKr; Fri, 31 Oct 2014 00:59:40 +0100 (CET)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+ by max.feld.cvut.cz (Postfix) with ESMTP id 8B8F95CCFF8;\r
+ Fri, 31 Oct 2014 00:59:40 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
+ (envelope-from <sojkam1@fel.cvut.cz>)\r
+ id 1Xjzcs-0005bK-QA; Fri, 31 Oct 2014 00:59:34 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 2/7] cli: Add support for parsing keyword-flag arguments\r
+Date: Fri, 31 Oct 2014 00:59:28 +0100\r
+Message-Id: <1414713573-21461-3-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <1414713573-21461-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1414713573-21461-1-git-send-email-sojkam1@fel.cvut.cz>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 30 Oct 2014 23:59:53 -0000\r
+\r
+From: Jani Nikula <jani@nikula.org>\r
+\r
+This allows having multiple --foo=bar --foo=baz options on the command\r
+line, with the corresponding values OR'd together.\r
+\r
+[Test added by Michal Sojka]\r
+---\r
+ command-line-arguments.c | 6 +++++-\r
+ command-line-arguments.h | 1 +\r
+ test/T410-argument-parsing.sh | 3 ++-\r
+ test/arg-test.c | 9 +++++++++\r
+ 4 files changed, 17 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/command-line-arguments.c b/command-line-arguments.c\r
+index 844d6c3..c6f7269 100644\r
+--- a/command-line-arguments.c\r
++++ b/command-line-arguments.c\r
+@@ -23,7 +23,10 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char\r
+ while (keywords->name) {\r
+ if (strcmp (arg_str, keywords->name) == 0) {\r
+ if (arg_desc->output_var) {\r
+- *((int *)arg_desc->output_var) = keywords->value;\r
++ if (arg_desc->opt_type == NOTMUCH_OPT_KEYWORD_FLAGS)\r
++ *((int *)arg_desc->output_var) |= keywords->value;\r
++ else\r
++ *((int *)arg_desc->output_var) = keywords->value;\r
+ }\r
+ return TRUE;\r
+ }\r
+@@ -152,6 +155,7 @@ parse_option (const char *arg,\r
+ \r
+ switch (try->opt_type) {\r
+ case NOTMUCH_OPT_KEYWORD:\r
++ case NOTMUCH_OPT_KEYWORD_FLAGS:\r
+ return _process_keyword_arg (try, next, value);\r
+ case NOTMUCH_OPT_BOOLEAN:\r
+ return _process_boolean_arg (try, next, value);\r
+diff --git a/command-line-arguments.h b/command-line-arguments.h\r
+index de1734a..6444129 100644\r
+--- a/command-line-arguments.h\r
++++ b/command-line-arguments.h\r
+@@ -8,6 +8,7 @@ enum notmuch_opt_type {\r
+ NOTMUCH_OPT_BOOLEAN, /* --verbose */\r
+ NOTMUCH_OPT_INT, /* --frob=8 */\r
+ NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */\r
++ NOTMUCH_OPT_KEYWORD_FLAGS, /* the above with values OR'd together */\r
+ NOTMUCH_OPT_STRING, /* --file=/tmp/gnarf.txt */\r
+ NOTMUCH_OPT_POSITION /* notmuch dump pos_arg */\r
+ };\r
+diff --git a/test/T410-argument-parsing.sh b/test/T410-argument-parsing.sh\r
+index 94e9087..2e5d7ae 100755\r
+--- a/test/T410-argument-parsing.sh\r
++++ b/test/T410-argument-parsing.sh\r
+@@ -3,9 +3,10 @@ test_description="argument parsing"\r
+ . ./test-lib.sh\r
+ \r
+ test_begin_subtest "sanity check"\r
+-$TEST_DIRECTORY/arg-test pos1 --keyword=one --string=foo pos2 --int=7 > OUTPUT\r
++$TEST_DIRECTORY/arg-test pos1 --keyword=one --string=foo pos2 --int=7 --flag=one --flag=three > OUTPUT\r
+ cat <<EOF > EXPECTED\r
+ keyword 1\r
++flags 5\r
+ int 7\r
+ string foo\r
+ positional arg 1 pos1\r
+diff --git a/test/arg-test.c b/test/arg-test.c\r
+index 6c49eac..736686d 100644\r
+--- a/test/arg-test.c\r
++++ b/test/arg-test.c\r
+@@ -7,6 +7,7 @@ int main(int argc, char **argv){\r
+ int opt_index=1;\r
+ \r
+ int kw_val=0;\r
++ int fl_val=0;\r
+ int int_val=0;\r
+ char *pos_arg1=NULL;\r
+ char *pos_arg2=NULL;\r
+@@ -17,6 +18,11 @@ int main(int argc, char **argv){\r
+ (notmuch_keyword_t []){ { "one", 1 },\r
+ { "two", 2 },\r
+ { 0, 0 } } },\r
++ { NOTMUCH_OPT_KEYWORD_FLAGS, &fl_val, "flag", 'f',\r
++ (notmuch_keyword_t []){ { "one", 1 << 0},\r
++ { "two", 1 << 1 },\r
++ { "three", 1 << 2 },\r
++ { 0, 0 } } },\r
+ { NOTMUCH_OPT_INT, &int_val, "int", 'i', 0},\r
+ { NOTMUCH_OPT_STRING, &string_val, "string", 's', 0},\r
+ { NOTMUCH_OPT_POSITION, &pos_arg1, 0,0, 0},\r
+@@ -31,6 +37,9 @@ int main(int argc, char **argv){\r
+ if (kw_val)\r
+ printf("keyword %d\n", kw_val);\r
+ \r
++ if (fl_val)\r
++ printf("flags %d\n", fl_val);\r
++\r
+ if (int_val)\r
+ printf("int %d\n", int_val);\r
+ \r
+-- \r
+2.1.1\r
+\r