1 Return-Path: <sojkam1@fel.cvut.cz>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 19A9B431FBC
\r
6 for <notmuch@notmuchmail.org>; Sun, 5 Oct 2014 13:52:46 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 7dYPN8j6gBGo for <notmuch@notmuchmail.org>;
\r
16 Sun, 5 Oct 2014 13:52:44 -0700 (PDT)
\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])
\r
18 by olra.theworths.org (Postfix) with ESMTP id E617B431FBF
\r
19 for <notmuch@notmuchmail.org>; Sun, 5 Oct 2014 13:52:38 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 4F88B3CFE94;
\r
22 Sun, 5 Oct 2014 22:52:36 +0200 (CEST)
\r
23 X-Virus-Scanned: IMAP STYX AMAVIS
\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])
\r
25 by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,
\r
27 with ESMTP id T4ayZKUsuqzQ; Sun, 5 Oct 2014 22:52:32 +0200 (CEST)
\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])
\r
29 by max.feld.cvut.cz (Postfix) with ESMTP id 9B33A3CFE9A;
\r
30 Sun, 5 Oct 2014 22:52:31 +0200 (CEST)
\r
31 Received: from wsh by steelpick.2x.cz with local (Exim 4.84)
\r
32 (envelope-from <sojkam1@fel.cvut.cz>)
\r
33 id 1Xasn2-0005E8-SD; Sun, 05 Oct 2014 22:52:24 +0200
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH v2 3/4] cli: Add support for parsing multiple keyword
\r
38 Date: Sun, 5 Oct 2014 22:51:58 +0200
\r
39 Message-Id: <1412542319-20017-4-git-send-email-sojkam1@fel.cvut.cz>
\r
40 X-Mailer: git-send-email 2.1.1
\r
41 In-Reply-To: <1412542319-20017-1-git-send-email-sojkam1@fel.cvut.cz>
\r
42 References: <874mvqxrnp.fsf@nikula.org>
\r
43 <1412542319-20017-1-git-send-email-sojkam1@fel.cvut.cz>
\r
44 X-BeenThere: notmuch@notmuchmail.org
\r
45 X-Mailman-Version: 2.1.13
\r
47 List-Id: "Use and development of the notmuch mail system."
\r
48 <notmuch.notmuchmail.org>
\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
50 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
52 List-Post: <mailto:notmuch@notmuchmail.org>
\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
55 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
56 X-List-Received-Date: Sun, 05 Oct 2014 20:52:46 -0000
\r
58 From: Jani Nikula <jani@nikula.org>
\r
60 This allows having multiple --foo=bar --foo=baz options on the command
\r
61 line, with the corresponding values OR'd together.
\r
63 [Test added by Michal Sojka]
\r
65 command-line-arguments.c | 6 +++++-
\r
66 command-line-arguments.h | 1 +
\r
67 test/T410-argument-parsing.sh | 3 ++-
\r
68 test/arg-test.c | 9 +++++++++
\r
69 4 files changed, 17 insertions(+), 2 deletions(-)
\r
71 diff --git a/command-line-arguments.c b/command-line-arguments.c
\r
72 index 844d6c3..c6f7269 100644
\r
73 --- a/command-line-arguments.c
\r
74 +++ b/command-line-arguments.c
\r
75 @@ -23,7 +23,10 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char
\r
76 while (keywords->name) {
\r
77 if (strcmp (arg_str, keywords->name) == 0) {
\r
78 if (arg_desc->output_var) {
\r
79 - *((int *)arg_desc->output_var) = keywords->value;
\r
80 + if (arg_desc->opt_type == NOTMUCH_OPT_KEYWORD_FLAGS)
\r
81 + *((int *)arg_desc->output_var) |= keywords->value;
\r
83 + *((int *)arg_desc->output_var) = keywords->value;
\r
87 @@ -152,6 +155,7 @@ parse_option (const char *arg,
\r
89 switch (try->opt_type) {
\r
90 case NOTMUCH_OPT_KEYWORD:
\r
91 + case NOTMUCH_OPT_KEYWORD_FLAGS:
\r
92 return _process_keyword_arg (try, next, value);
\r
93 case NOTMUCH_OPT_BOOLEAN:
\r
94 return _process_boolean_arg (try, next, value);
\r
95 diff --git a/command-line-arguments.h b/command-line-arguments.h
\r
96 index de1734a..085a492 100644
\r
97 --- a/command-line-arguments.h
\r
98 +++ b/command-line-arguments.h
\r
99 @@ -8,6 +8,7 @@ enum notmuch_opt_type {
\r
100 NOTMUCH_OPT_BOOLEAN, /* --verbose */
\r
101 NOTMUCH_OPT_INT, /* --frob=8 */
\r
102 NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */
\r
103 + NOTMUCH_OPT_KEYWORD_FLAGS, /* the above with values OR'd together */
\r
104 NOTMUCH_OPT_STRING, /* --file=/tmp/gnarf.txt */
\r
105 NOTMUCH_OPT_POSITION /* notmuch dump pos_arg */
\r
107 diff --git a/test/T410-argument-parsing.sh b/test/T410-argument-parsing.sh
\r
108 index 94e9087..2e5d7ae 100755
\r
109 --- a/test/T410-argument-parsing.sh
\r
110 +++ b/test/T410-argument-parsing.sh
\r
111 @@ -3,9 +3,10 @@ test_description="argument parsing"
\r
114 test_begin_subtest "sanity check"
\r
115 -$TEST_DIRECTORY/arg-test pos1 --keyword=one --string=foo pos2 --int=7 > OUTPUT
\r
116 +$TEST_DIRECTORY/arg-test pos1 --keyword=one --string=foo pos2 --int=7 --flag=one --flag=three > OUTPUT
\r
117 cat <<EOF > EXPECTED
\r
122 positional arg 1 pos1
\r
123 diff --git a/test/arg-test.c b/test/arg-test.c
\r
124 index 6c49eac..736686d 100644
\r
125 --- a/test/arg-test.c
\r
126 +++ b/test/arg-test.c
\r
127 @@ -7,6 +7,7 @@ int main(int argc, char **argv){
\r
133 char *pos_arg1=NULL;
\r
134 char *pos_arg2=NULL;
\r
135 @@ -17,6 +18,11 @@ int main(int argc, char **argv){
\r
136 (notmuch_keyword_t []){ { "one", 1 },
\r
139 + { NOTMUCH_OPT_KEYWORD_FLAGS, &fl_val, "flag", 'f',
\r
140 + (notmuch_keyword_t []){ { "one", 1 << 0},
\r
141 + { "two", 1 << 1 },
\r
142 + { "three", 1 << 2 },
\r
144 { NOTMUCH_OPT_INT, &int_val, "int", 'i', 0},
\r
145 { NOTMUCH_OPT_STRING, &string_val, "string", 's', 0},
\r
146 { NOTMUCH_OPT_POSITION, &pos_arg1, 0,0, 0},
\r
147 @@ -31,6 +37,9 @@ int main(int argc, char **argv){
\r
149 printf("keyword %d\n", kw_val);
\r
152 + printf("flags %d\n", fl_val);
\r
155 printf("int %d\n", int_val);
\r