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 14D90431FCB
\r
6 for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 14:54:45 -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 VMS7oJngn0PC for <notmuch@notmuchmail.org>;
\r
16 Fri, 31 Oct 2014 14:54:39 -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 A9123431FD2
\r
19 for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 14:54:22 -0700 (PDT)
\r
20 Received: from localhost (unknown [192.168.200.7])
\r
21 by max.feld.cvut.cz (Postfix) with ESMTP id 233293D3E93
\r
22 for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 22:54:22 +0100 (CET)
\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
26 port 10044) with ESMTP id wYSfkRVW90I3 for <notmuch@notmuchmail.org>;
\r
27 Fri, 31 Oct 2014 22:54:18 +0100 (CET)
\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 7CF315CD110
\r
30 for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 22:54:14 +0100 (CET)
\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 1XkK92-0007hh-MF; Fri, 31 Oct 2014 22:54:08 +0100
\r
34 From: Michal Sojka <sojkam1@fel.cvut.cz>
\r
35 To: notmuch@notmuchmail.org
\r
36 Subject: [PATCH v6 2/7] cli: Add support for parsing keyword-flag arguments
\r
37 Date: Fri, 31 Oct 2014 22:53:56 +0100
\r
38 Message-Id: <1414792441-29555-3-git-send-email-sojkam1@fel.cvut.cz>
\r
39 X-Mailer: git-send-email 2.1.1
\r
40 In-Reply-To: <1414792441-29555-1-git-send-email-sojkam1@fel.cvut.cz>
\r
41 References: <1414792441-29555-1-git-send-email-sojkam1@fel.cvut.cz>
\r
42 X-BeenThere: notmuch@notmuchmail.org
\r
43 X-Mailman-Version: 2.1.13
\r
45 List-Id: "Use and development of the notmuch mail system."
\r
46 <notmuch.notmuchmail.org>
\r
47 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
49 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
50 List-Post: <mailto:notmuch@notmuchmail.org>
\r
51 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
52 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
53 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
54 X-List-Received-Date: Fri, 31 Oct 2014 21:54:45 -0000
\r
56 From: Jani Nikula <jani@nikula.org>
\r
58 This allows having multiple --foo=bar --foo=baz options on the command
\r
59 line, with the corresponding values OR'd together.
\r
61 [Test added by Michal Sojka]
\r
63 command-line-arguments.c | 6 +++++-
\r
64 command-line-arguments.h | 1 +
\r
65 test/T410-argument-parsing.sh | 3 ++-
\r
66 test/arg-test.c | 9 +++++++++
\r
67 4 files changed, 17 insertions(+), 2 deletions(-)
\r
69 diff --git a/command-line-arguments.c b/command-line-arguments.c
\r
70 index 844d6c3..c6f7269 100644
\r
71 --- a/command-line-arguments.c
\r
72 +++ b/command-line-arguments.c
\r
73 @@ -23,7 +23,10 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char
\r
74 while (keywords->name) {
\r
75 if (strcmp (arg_str, keywords->name) == 0) {
\r
76 if (arg_desc->output_var) {
\r
77 - *((int *)arg_desc->output_var) = keywords->value;
\r
78 + if (arg_desc->opt_type == NOTMUCH_OPT_KEYWORD_FLAGS)
\r
79 + *((int *)arg_desc->output_var) |= keywords->value;
\r
81 + *((int *)arg_desc->output_var) = keywords->value;
\r
85 @@ -152,6 +155,7 @@ parse_option (const char *arg,
\r
87 switch (try->opt_type) {
\r
88 case NOTMUCH_OPT_KEYWORD:
\r
89 + case NOTMUCH_OPT_KEYWORD_FLAGS:
\r
90 return _process_keyword_arg (try, next, value);
\r
91 case NOTMUCH_OPT_BOOLEAN:
\r
92 return _process_boolean_arg (try, next, value);
\r
93 diff --git a/command-line-arguments.h b/command-line-arguments.h
\r
94 index de1734a..6444129 100644
\r
95 --- a/command-line-arguments.h
\r
96 +++ b/command-line-arguments.h
\r
97 @@ -8,6 +8,7 @@ enum notmuch_opt_type {
\r
98 NOTMUCH_OPT_BOOLEAN, /* --verbose */
\r
99 NOTMUCH_OPT_INT, /* --frob=8 */
\r
100 NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */
\r
101 + NOTMUCH_OPT_KEYWORD_FLAGS, /* the above with values OR'd together */
\r
102 NOTMUCH_OPT_STRING, /* --file=/tmp/gnarf.txt */
\r
103 NOTMUCH_OPT_POSITION /* notmuch dump pos_arg */
\r
105 diff --git a/test/T410-argument-parsing.sh b/test/T410-argument-parsing.sh
\r
106 index 94e9087..2e5d7ae 100755
\r
107 --- a/test/T410-argument-parsing.sh
\r
108 +++ b/test/T410-argument-parsing.sh
\r
109 @@ -3,9 +3,10 @@ test_description="argument parsing"
\r
112 test_begin_subtest "sanity check"
\r
113 -$TEST_DIRECTORY/arg-test pos1 --keyword=one --string=foo pos2 --int=7 > OUTPUT
\r
114 +$TEST_DIRECTORY/arg-test pos1 --keyword=one --string=foo pos2 --int=7 --flag=one --flag=three > OUTPUT
\r
115 cat <<EOF > EXPECTED
\r
120 positional arg 1 pos1
\r
121 diff --git a/test/arg-test.c b/test/arg-test.c
\r
122 index 6c49eac..736686d 100644
\r
123 --- a/test/arg-test.c
\r
124 +++ b/test/arg-test.c
\r
125 @@ -7,6 +7,7 @@ int main(int argc, char **argv){
\r
131 char *pos_arg1=NULL;
\r
132 char *pos_arg2=NULL;
\r
133 @@ -17,6 +18,11 @@ int main(int argc, char **argv){
\r
134 (notmuch_keyword_t []){ { "one", 1 },
\r
137 + { NOTMUCH_OPT_KEYWORD_FLAGS, &fl_val, "flag", 'f',
\r
138 + (notmuch_keyword_t []){ { "one", 1 << 0},
\r
139 + { "two", 1 << 1 },
\r
140 + { "three", 1 << 2 },
\r
142 { NOTMUCH_OPT_INT, &int_val, "int", 'i', 0},
\r
143 { NOTMUCH_OPT_STRING, &string_val, "string", 's', 0},
\r
144 { NOTMUCH_OPT_POSITION, &pos_arg1, 0,0, 0},
\r
145 @@ -31,6 +37,9 @@ int main(int argc, char **argv){
\r
147 printf("keyword %d\n", kw_val);
\r
150 + printf("flags %d\n", fl_val);
\r
153 printf("int %d\n", int_val);
\r