1 Return-Path: <chris@chris-wilson.co.uk>
\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 7203A431FBC
\r
6 for <notmuch@notmuchmail.org>; Fri, 15 Jan 2010 02:14:00 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.825 tagged_above=-999 required=5 tests=[AWL=1.174,
\r
12 BAYES_50=0.001, RCVD_IN_DNSWL_MED=-4] autolearn=ham
\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 rBMqHZMtURkN for <notmuch@notmuchmail.org>;
\r
16 Fri, 15 Jan 2010 02:13:59 -0800 (PST)
\r
17 Received: from fmsmga101.fm.intel.com (mga05.intel.com [192.55.52.89])
\r
18 by olra.theworths.org (Postfix) with ESMTP id 3F05F431FAE
\r
19 for <notmuch@notmuchmail.org>; Fri, 15 Jan 2010 02:13:59 -0800 (PST)
\r
20 Received: from fmsmga001.fm.intel.com ([10.253.24.23])
\r
21 by fmsmga101.fm.intel.com with ESMTP; 15 Jan 2010 02:13:37 -0800
\r
23 X-IronPort-AV: E=Sophos;i="4.49,281,1262592000"; d="scan'208";a="764481457"
\r
24 Received: from unknown (HELO localhost.localdomain) ([10.255.17.127])
\r
25 by fmsmga001.fm.intel.com with ESMTP; 15 Jan 2010 02:13:55 -0800
\r
26 From: Chris Wilson <chris@chris-wilson.co.uk>
\r
27 To: notmuch@notmuchmail.org
\r
28 Date: Fri, 15 Jan 2010 10:13:50 +0000
\r
29 Message-Id: <1263550430-14223-1-git-send-email-chris@chris-wilson.co.uk>
\r
30 X-Mailer: git-send-email 1.6.6
\r
31 Subject: [notmuch] [PATCH] [RFC] notmuch search: Return a non-zero exitcode
\r
32 if the search returns no hits.
\r
33 X-BeenThere: notmuch@notmuchmail.org
\r
34 X-Mailman-Version: 2.1.13
\r
36 List-Id: "Use and development of the notmuch mail system."
\r
37 <notmuch.notmuchmail.org>
\r
38 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
39 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
41 List-Post: <mailto:notmuch@notmuchmail.org>
\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
43 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
44 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
45 X-List-Received-Date: Fri, 15 Jan 2010 10:14:00 -0000
\r
47 If the user is explicitly searching for a message, then if notmuch
\r
48 fails to find it, it is useful to set a failure exit code. This makes it
\r
49 easier for scripting. However, we will want to then distinguish between
\r
50 fatal errors (such as out-of-memory, invalid arguments, corrupt db, etc)
\r
51 from the simple no message. To that end, we introduce a set of
\r
52 enumerated exit-codes which may prove useful to use consistently across
\r
53 notmuch. (I'm not that convinced highly differentiated errors is
\r
54 particularly useful, though separate CONFIG_ERROR and DATABASE_ERROR
\r
55 would seem to have value for scripts.)
\r
57 notmuch-search.c | 34 ++++++++++++++++++++++++----------
\r
58 1 files changed, 24 insertions(+), 10 deletions(-)
\r
60 diff --git a/notmuch-search.c b/notmuch-search.c
\r
61 index dc44eb6..6ca903b 100644
\r
62 --- a/notmuch-search.c
\r
63 +++ b/notmuch-search.c
\r
66 #include "notmuch-client.h"
\r
69 +/* XXX After some review, make these universal? */
\r
71 + NOTMUCH_EXIT_SUCCESS = 0,
\r
72 + NOTMUCH_EXIT_NOT_FOUND,
\r
73 + NOTMUCH_EXIT_INVALID_ARGUMENT,
\r
74 + NOTMUCH_EXIT_SYSTEM_ERROR, /* XXX just out-of-memory? */
\r
75 + NOTMUCH_EXIT_CONFIG_ERROR,
\r
76 + NOTMUCH_EXIT_DATABASE_ERROR,
\r
80 do_search_threads (const void *ctx,
\r
81 notmuch_query_t *query,
\r
82 notmuch_sort_t sort)
\r
83 @@ -30,6 +40,7 @@ do_search_threads (const void *ctx,
\r
84 notmuch_tags_t *tags;
\r
86 const char *relative_date;
\r
89 for (threads = notmuch_query_search_threads (query);
\r
90 notmuch_threads_has_more (threads);
\r
91 @@ -67,7 +78,10 @@ do_search_threads (const void *ctx,
\r
94 notmuch_thread_destroy (thread);
\r
102 @@ -94,11 +108,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
103 sort = NOTMUCH_SORT_NEWEST_FIRST;
\r
105 fprintf (stderr, "Invalid value for --sort: %s\n", opt);
\r
107 + return NOTMUCH_EXIT_INVALID_ARGUMENT;
\r
110 fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
\r
112 + return NOTMUCH_EXIT_INVALID_ARGUMENT;
\r
116 @@ -107,35 +121,35 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
\r
118 config = notmuch_config_open (ctx, NULL, NULL);
\r
119 if (config == NULL)
\r
121 + return NOTMUCH_EXIT_CONFIG_ERROR;
\r
123 notmuch = notmuch_database_open (notmuch_config_get_database_path (config),
\r
124 NOTMUCH_DATABASE_MODE_READ_ONLY);
\r
125 if (notmuch == NULL)
\r
127 + return NOTMUCH_EXIT_DATABASE_ERROR;
\r
129 query_str = query_string_from_args (ctx, argc, argv);
\r
130 if (query_str == NULL) {
\r
131 fprintf (stderr, "Out of memory.\n");
\r
133 + return NOTMUCH_EXIT_SYSTEM_ERROR;
\r
135 if (*query_str == '\0') {
\r
136 fprintf (stderr, "Error: notmuch search requires at least one search term.\n");
\r
138 + return NOTMUCH_EXIT_INVALID_ARGUMENT;
\r
141 query = notmuch_query_create (notmuch, query_str);
\r
142 if (query == NULL) {
\r
143 fprintf (stderr, "Out of memory\n");
\r
145 + return NOTMUCH_EXIT_SYSTEM_ERROR;
\r
148 notmuch_query_set_sort (query, sort);
\r
150 - do_search_threads (ctx, query, sort);
\r
151 + i = do_search_threads (ctx, query, sort);
\r
153 notmuch_query_destroy (query);
\r
154 notmuch_database_close (notmuch);
\r
157 + return i ? NOTMUCH_EXIT_SUCCESS : NOTMUCH_EXIT_NOT_FOUND;
\r