1 Return-Path: <bremner@tethera.net>
\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 arlo.cworth.org (Postfix) with ESMTP id 6BDAD6DE092B
\r
6 for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:56:08 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.029 tagged_above=-999 required=5
\r
12 tests=[AWL=-0.018, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id c5M-Iw1F0ae5 for <notmuch@notmuchmail.org>;
\r
17 Tue, 22 Mar 2016 03:56:00 -0700 (PDT)
\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id D4D7E6DE0297
\r
20 for <notmuch@notmuchmail.org>; Tue, 22 Mar 2016 03:55:25 -0700 (PDT)
\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)
\r
22 (envelope-from <bremner@tethera.net>)
\r
23 id 1aiJyj-00015k-9C; Tue, 22 Mar 2016 06:56:01 -0400
\r
24 Received: (nullmailer pid 14089 invoked by uid 1000);
\r
25 Tue, 22 Mar 2016 10:55:11 -0000
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [PATCH 11/13] CLI: add notmuch-config support for named queries
\r
29 Date: Tue, 22 Mar 2016 07:54:52 -0300
\r
30 Message-Id: <1458644094-13951-12-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.7.0
\r
32 In-Reply-To: <1458644094-13951-1-git-send-email-david@tethera.net>
\r
33 References: <1458644094-13951-1-git-send-email-david@tethera.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Tue, 22 Mar 2016 10:56:08 -0000
\r
48 Most of the infrastructure here is general, only the validation/dispatch
\r
49 is hardcoded to a particular prefix.
\r
51 A notable change in behaviour is that notmuch-config now opens the
\r
52 database e.g. on every call to list, which fails with an error message
\r
53 if the database doesn't exit yet.
\r
55 doc/man1/notmuch-config.rst | 5 +++
\r
56 notmuch-config.c | 88 ++++++++++++++++++++++++++++++++++++++++++++-
\r
57 test/Makefile.local | 2 +-
\r
58 test/T030-config.sh | 12 ++++---
\r
59 test/T600-named-queries.sh | 53 +++++++++++++++++++++++++++
\r
60 test/test-lib.sh | 5 +++
\r
61 6 files changed, 158 insertions(+), 7 deletions(-)
\r
62 create mode 100755 test/T600-named-queries.sh
\r
64 diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
\r
65 index 40c1272..98b3c1a 100644
\r
66 --- a/doc/man1/notmuch-config.rst
\r
67 +++ b/doc/man1/notmuch-config.rst
\r
68 @@ -132,6 +132,11 @@ The available configuration items are described below.
\r
74 + Expansion for named query called <name>. See
\r
75 + **notmuch-search-terms(7)** for more information about named
\r
80 diff --git a/notmuch-config.c b/notmuch-config.c
\r
81 index cfc549d..121fec6 100644
\r
82 --- a/notmuch-config.c
\r
83 +++ b/notmuch-config.c
\r
84 @@ -751,6 +751,28 @@ _item_split (char *item, char **group, char **key)
\r
87 #define OPTION_PREFIX "options."
\r
88 +#define QUERY_PREFIX "query."
\r
91 +_print_db_config(notmuch_config_t *config, const char *name)
\r
93 + notmuch_database_t *notmuch;
\r
96 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
97 + NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
98 + return EXIT_FAILURE;
\r
100 + /* XXX Handle UUID mismatch? */
\r
102 + if (print_status_database ("notmuch config", notmuch,
\r
103 + notmuch_database_get_config (notmuch, name, &val)))
\r
104 + return EXIT_FAILURE;
\r
108 + return EXIT_SUCCESS;
\r
112 notmuch_config_command_get (notmuch_config_t *config, char *item)
\r
113 @@ -778,6 +800,8 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)
\r
114 } else if (STRNCMP_LITERAL (item, OPTION_PREFIX) == 0) {
\r
116 notmuch_options_get (item + strlen (OPTION_PREFIX)) ? "true" : "false");
\r
117 + } else if (STRNCMP_LITERAL (item, QUERY_PREFIX) == 0) {
\r
118 + return _print_db_config (config, item);
\r
122 @@ -805,6 +829,39 @@ notmuch_config_command_get (notmuch_config_t *config, char *item)
\r
126 +_set_db_config(notmuch_config_t *config, const char *key, int argc, char **argv)
\r
128 + notmuch_database_t *notmuch;
\r
129 + const char *val = "";
\r
132 + /* XXX handle lists? */
\r
133 + fprintf (stderr, "notmuch config set: at most one value expected for %s\n", key);
\r
134 + return EXIT_FAILURE;
\r
141 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
142 + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
\r
143 + return EXIT_FAILURE;
\r
145 + /* XXX Handle UUID mismatch? */
\r
147 + if (print_status_database ("notmuch config", notmuch,
\r
148 + notmuch_database_set_config (notmuch, key, val)))
\r
149 + return EXIT_FAILURE;
\r
151 + if (print_status_database ("notmuch config", notmuch,
\r
152 + notmuch_database_close (notmuch)))
\r
153 + return EXIT_FAILURE;
\r
155 + return EXIT_SUCCESS;
\r
159 notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char *argv[])
\r
162 @@ -814,6 +871,10 @@ notmuch_config_command_set (notmuch_config_t *config, char *item, int argc, char
\r
166 + if (STRNCMP_LITERAL (item, QUERY_PREFIX) == 0) {
\r
167 + return _set_db_config (config, item, argc, argv);
\r
170 if (_item_split (item, &group, &key))
\r
173 @@ -850,6 +911,31 @@ _notmuch_config_list_options () {
\r
177 +_list_db_config (notmuch_config_t *config)
\r
179 + notmuch_database_t *notmuch;
\r
180 + notmuch_config_list_t *list;
\r
182 + if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
183 + NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
184 + return EXIT_FAILURE;
\r
186 + /* XXX Handle UUID mismatch? */
\r
189 + if (print_status_database ("notmuch config", notmuch,
\r
190 + notmuch_database_get_config_list (notmuch, "", &list)))
\r
191 + return EXIT_FAILURE;
\r
193 + for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
\r
194 + printf("%s=%s\n", notmuch_config_list_key (list), notmuch_config_list_value(list));
\r
196 + notmuch_config_list_destroy (list);
\r
198 + return EXIT_SUCCESS;
\r
202 notmuch_config_command_list (notmuch_config_t *config)
\r
205 @@ -885,7 +971,7 @@ notmuch_config_command_list (notmuch_config_t *config)
\r
206 g_strfreev (groups);
\r
208 _notmuch_config_list_options ();
\r
210 + return _list_db_config (config);
\r
214 diff --git a/test/Makefile.local b/test/Makefile.local
\r
215 index 30d420e..8c55441 100644
\r
216 --- a/test/Makefile.local
\r
217 +++ b/test/Makefile.local
\r
218 @@ -19,7 +19,7 @@ $(dir)/hex-xcode: $(dir)/hex-xcode.o command-line-arguments.o util/libutil.a
\r
219 $(call quiet,CC) $^ -o $@ $(LDFLAGS) $(TALLOC_LDFLAGS)
\r
221 random_corpus_deps = $(dir)/random-corpus.o $(dir)/database-test.o \
\r
222 - notmuch-config.o command-line-arguments.o \
\r
223 + notmuch-config.o status.o command-line-arguments.o \
\r
224 lib/libnotmuch.a util/libutil.a \
\r
225 parse-time-string/libparse-time-string.a
\r
227 diff --git a/test/T030-config.sh b/test/T030-config.sh
\r
228 index c37ba21..39ee885 100755
\r
229 --- a/test/T030-config.sh
\r
230 +++ b/test/T030-config.sh
\r
231 @@ -43,10 +43,10 @@ notmuch config set foo.nonexistent
\r
232 test_expect_equal "$(notmuch config get foo.nonexistent)" ""
\r
234 test_begin_subtest "List all items"
\r
235 -notmuch config set database.path "/canonical/path"
\r
236 -output=$(notmuch config list | notmuch_options_sanitize)
\r
237 -test_expect_equal "$output" "\
\r
238 -database.path=/canonical/path
\r
239 +notmuch config list 2>&1 | notmuch_config_sanitize > OUTPUT
\r
240 +cat <<EOF > EXPECTED
\r
241 +Error opening database at MAIL_DIR/.notmuch: No such file or directory
\r
242 +database.path=MAIL_DIR
\r
243 user.name=Notmuch Test Suite
\r
244 user.primary_email=test_suite@notmuchmail.org
\r
245 user.other_email=test_suite_other@notmuchmail.org;test_suite@otherdomain.org
\r
246 @@ -58,7 +58,9 @@ crypto.gpg_path=gpg
\r
247 foo.string=this is another string value
\r
248 foo.list=this;is another;list value;
\r
249 options.compact=something
\r
250 -options.field_processor=something"
\r
251 +options.field_processor=something
\r
253 +test_expect_equal_file EXPECTED OUTPUT
\r
255 test_begin_subtest "Top level --config=FILE option"
\r
256 cp "${NOTMUCH_CONFIG}" alt-config
\r
257 diff --git a/test/T600-named-queries.sh b/test/T600-named-queries.sh
\r
258 new file mode 100755
\r
259 index 0000000..0922620
\r
261 +++ b/test/T600-named-queries.sh
\r
263 +#!/usr/bin/env bash
\r
264 +test_description='named queries'
\r
265 +. ./test-lib.sh || exit 1
\r
267 +QUERYSTR="date:2009-11-18..2009-11-18 and tag:unread"
\r
269 +test_expect_code 1 "error adding named query before initializing DB" \
\r
270 + "notmuch config set query.test \"$QUERYSTR\""
\r
274 +test_expect_success "adding named query" \
\r
275 + "notmuch config set query.test \"$QUERYSTR\""
\r
277 +QUERYSTR2="query:test and subject:Maildir"
\r
278 +test_expect_success "adding nested named query" \
\r
279 + "notmuch config set query.test2 \"$QUERYSTR2\""
\r
281 +test_begin_subtest "retrieve named query"
\r
282 +output=$(notmuch config get query.test)
\r
283 +test_expect_equal "$QUERYSTR" "$output"
\r
285 +test_begin_subtest "List all queries"
\r
286 +notmuch config list | grep ^query | notmuch_config_sanitize > OUTPUT
\r
287 +cat <<EOF > EXPECTED
\r
288 +query.test=date:2009-11-18..2009-11-18 and tag:unread
\r
289 +query.test2=query:test and subject:Maildir
\r
291 +test_expect_equal_file EXPECTED OUTPUT
\r
293 +test_begin_subtest "dump named queries"
\r
294 +notmuch dump | grep '^#@' > OUTPUT
\r
295 +cat<<EOF > QUERIES.BEFORE
\r
296 +#@ query.test date%3a2009-11-18..2009-11-18%20and%20tag%3aunread
\r
297 +#@ query.test2 query%3atest%20and%20subject%3aMaildir
\r
299 +test_expect_equal_file QUERIES.BEFORE OUTPUT
\r
301 +test_begin_subtest "delete named queries"
\r
302 +notmuch dump > BEFORE
\r
303 +notmuch config set query.test
\r
304 +notmuch dump | grep '^#@' > OUTPUT
\r
305 +cat<<EOF > EXPECTED
\r
306 +#@ query.test2 query%3atest%20and%20subject%3aMaildir
\r
308 +test_expect_equal_file EXPECTED OUTPUT
\r
310 +test_begin_subtest "restore named queries"
\r
311 +notmuch restore < BEFORE
\r
312 +notmuch dump | grep '^#@' > OUTPUT
\r
313 +test_expect_equal_file QUERIES.BEFORE OUTPUT
\r
316 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
317 index 98abbe2..00df2bd 100644
\r
318 --- a/test/test-lib.sh
\r
319 +++ b/test/test-lib.sh
\r
320 @@ -745,6 +745,11 @@ notmuch_options_sanitize ()
\r
321 sed 's/^options[.]\(.*\)=.*$/options.\1=something/'
\r
324 +notmuch_config_sanitize ()
\r
326 + notmuch_dir_sanitize | notmuch_options_sanitize
\r
329 # End of notmuch helper functions
\r
331 # Use test_set_prereq to tell that a particular prerequisite is available.
\r