1 Return-Path: <jani@nikula.org>
\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 64D34431FC7
\r
6 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 13:55:22 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id mKNPant9o1wr for <notmuch@notmuchmail.org>;
\r
17 Sun, 3 Mar 2013 13:55:17 -0800 (PST)
\r
18 Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com
\r
19 [209.85.217.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 9E3ED431FAF
\r
22 for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 13:55:17 -0800 (PST)
\r
23 Received: by mail-lb0-f176.google.com with SMTP id s4so3423317lbc.7
\r
24 for <notmuch@notmuchmail.org>; Sun, 03 Mar 2013 13:55:16 -0800 (PST)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=google.com; s=20120113;
\r
27 h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to
\r
28 :references:in-reply-to:references:x-gm-message-state;
\r
29 bh=xqu8g7GrmnFPNTesByK6E25F/+SB9aDiPNRFZ89INrk=;
\r
30 b=gwbKA49TNfzTAfybaXe/8AIJcV21WF8ktSw2dkus0lifOuyEMUbE9Dlgs3vAqaqbqx
\r
31 6dJpH26P21wxTmvoZ2oymv0Q7UiM5Gqcv4G8nAWyTymmHgHfC4TPBILdkDqYhtAe37+L
\r
32 +i53IxEpOjfy45VNOQmd4XYmiOugOAClu/NJpX7VavUSm6IWfovNvfBqHAmDrUMmitw4
\r
33 RRkwmrUoEwcSXMXXuy2APHK/dfGNk+KnwH4VlVRrXgVLfcYlSG8ueWvkdt50k/5OfBy8
\r
34 oqsSQe76IPp4N8QTlq38hAdykNQ/Yuu9pkVFAtaq+puR0xJPf6jdnZx8U5BOj9Bnc1Xh
\r
36 X-Received: by 10.112.88.35 with SMTP id bd3mr3672025lbb.56.1362347716050;
\r
37 Sun, 03 Mar 2013 13:55:16 -0800 (PST)
\r
38 Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.
\r
40 by mx.google.com with ESMTPS id v7sm6609588lbg.13.2013.03.03.13.55.14
\r
41 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
42 Sun, 03 Mar 2013 13:55:15 -0800 (PST)
\r
43 From: Jani Nikula <jani@nikula.org>
\r
44 To: notmuch@notmuchmail.org
\r
45 Subject: [PATCH v2 1/6] cli: abstract subcommand finding into a new function
\r
46 Date: Sun, 3 Mar 2013 23:55:05 +0200
\r
48 <a3d3c306c0c1f0d118819e4cfd143a4bc1f8457e.1362347362.git.jani@nikula.org>
\r
49 X-Mailer: git-send-email 1.7.10.4
\r
50 In-Reply-To: <cover.1362347362.git.jani@nikula.org>
\r
51 References: <cover.1362347362.git.jani@nikula.org>
\r
52 In-Reply-To: <cover.1362347362.git.jani@nikula.org>
\r
53 References: <cover.1362347362.git.jani@nikula.org>
\r
55 ALoCoQlKP2nQ68kPj5Dz9xtsnYvtNnHbPBMJY4UK9qVA2nj56Hxl/cwzZoOreqYbRKP+04I+BpwU
\r
56 X-BeenThere: notmuch@notmuchmail.org
\r
57 X-Mailman-Version: 2.1.13
\r
59 List-Id: "Use and development of the notmuch mail system."
\r
60 <notmuch.notmuchmail.org>
\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
64 List-Post: <mailto:notmuch@notmuchmail.org>
\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
68 X-List-Received-Date: Sun, 03 Mar 2013 21:55:23 -0000
\r
72 notmuch.c | 78 +++++++++++++++++++++++++++++++------------------------------
\r
73 1 file changed, 40 insertions(+), 38 deletions(-)
\r
75 diff --git a/notmuch.c b/notmuch.c
\r
76 index cfb009b..3dff6d4 100644
\r
79 @@ -70,6 +70,18 @@ static command_t commands[] = {
\r
80 "This message, or more detailed help for the named command." }
\r
84 +find_command (const char *name)
\r
88 + for (i = 0; i < ARRAY_SIZE (commands); i++)
\r
89 + if (strcmp (name, commands[i].name) == 0)
\r
90 + return &commands[i];
\r
95 int notmuch_format_version;
\r
98 @@ -139,7 +151,6 @@ static int
\r
99 notmuch_help_command (void *ctx, int argc, char *argv[])
\r
101 command_t *command;
\r
104 argc--; argv++; /* Ignore "help" */
\r
106 @@ -158,13 +169,10 @@ notmuch_help_command (void *ctx, int argc, char *argv[])
\r
110 - for (i = 0; i < ARRAY_SIZE (commands); i++) {
\r
111 - command = &commands[i];
\r
113 - if (strcmp (argv[0], command->name) == 0) {
\r
114 - char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);
\r
117 + command = find_command (argv[0]);
\r
119 + char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);
\r
123 if (strcmp (argv[0], "search-terms") == 0) {
\r
124 @@ -247,10 +255,11 @@ int
\r
125 main (int argc, char *argv[])
\r
128 + char *talloc_report;
\r
129 command_t *command;
\r
131 notmuch_bool_t print_help=FALSE, print_version=FALSE;
\r
135 notmuch_opt_desc_t options[] = {
\r
136 { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },
\r
137 @@ -285,39 +294,32 @@ main (int argc, char *argv[])
\r
141 - for (i = 0; i < ARRAY_SIZE (commands); i++) {
\r
142 - command = &commands[i];
\r
144 - if (strcmp (argv[opt_index], command->name) == 0) {
\r
146 - char *talloc_report;
\r
148 - ret = (command->function)(local, argc - opt_index, argv + opt_index);
\r
150 - talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");
\r
152 - /* this relies on the previous call to
\r
153 - * talloc_enable_null_tracking */
\r
155 - if (talloc_report && strcmp (talloc_report, "") != 0) {
\r
156 - FILE *report = fopen (talloc_report, "w");
\r
158 - talloc_report_full (NULL, report);
\r
161 - fprintf (stderr, "ERROR: unable to write talloc log. ");
\r
162 - perror (talloc_report);
\r
165 + command = find_command (argv[opt_index]);
\r
167 + fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
\r
168 + argv[opt_index]);
\r
173 + ret = (command->function)(local, argc - opt_index, argv + opt_index);
\r
175 + talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");
\r
176 + if (talloc_report && strcmp (talloc_report, "") != 0) {
\r
177 + /* this relies on the previous call to
\r
178 + * talloc_enable_null_tracking
\r
181 + FILE *report = fopen (talloc_report, "w");
\r
183 + talloc_report_full (NULL, report);
\r
186 + fprintf (stderr, "ERROR: unable to write talloc log. ");
\r
187 + perror (talloc_report);
\r
191 - fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",
\r
194 talloc_free (local);
\r