Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / a0 / d964f5ca76a7558e6557a44560dd477ec21f05
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
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \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
35         Vjmg==\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
39         [80.223.81.27])\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
47 Message-Id:\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
54 X-Gm-Message-State:\r
55  ALoCoQlKP2nQ68kPj5Dz9xtsnYvtNnHbPBMJY4UK9qVA2nj56Hxl/cwzZoOreqYbRKP+04I+BpwU\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\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
69 \r
70 Clean up code.\r
71 ---\r
72  notmuch.c |   78 +++++++++++++++++++++++++++++++------------------------------\r
73  1 file changed, 40 insertions(+), 38 deletions(-)\r
74 \r
75 diff --git a/notmuch.c b/notmuch.c\r
76 index cfb009b..3dff6d4 100644\r
77 --- a/notmuch.c\r
78 +++ b/notmuch.c\r
79 @@ -70,6 +70,18 @@ static command_t commands[] = {\r
80        "This message, or more detailed help for the named command." }\r
81  };\r
82  \r
83 +static command_t *\r
84 +find_command (const char *name)\r
85 +{\r
86 +    size_t i;\r
87 +\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
91 +\r
92 +    return NULL;\r
93 +}\r
94 +\r
95  int notmuch_format_version;\r
96  \r
97  static void\r
98 @@ -139,7 +151,6 @@ static int\r
99  notmuch_help_command (void *ctx, int argc, char *argv[])\r
100  {\r
101      command_t *command;\r
102 -    unsigned int i;\r
103  \r
104      argc--; argv++; /* Ignore "help" */\r
105  \r
106 @@ -158,13 +169,10 @@ notmuch_help_command (void *ctx, int argc, char *argv[])\r
107         return 0;\r
108      }\r
109  \r
110 -    for (i = 0; i < ARRAY_SIZE (commands); i++) {\r
111 -       command = &commands[i];\r
112 -\r
113 -       if (strcmp (argv[0], command->name) == 0) {\r
114 -           char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);\r
115 -           exec_man (page);\r
116 -       }\r
117 +    command = find_command (argv[0]);\r
118 +    if (command) {\r
119 +       char *page = talloc_asprintf (ctx, "notmuch-%s", command->name);\r
120 +       exec_man (page);\r
121      }\r
122  \r
123      if (strcmp (argv[0], "search-terms") == 0) {\r
124 @@ -247,10 +255,11 @@ int\r
125  main (int argc, char *argv[])\r
126  {\r
127      void *local;\r
128 +    char *talloc_report;\r
129      command_t *command;\r
130 -    unsigned int i;\r
131      notmuch_bool_t print_help=FALSE, print_version=FALSE;\r
132      int opt_index;\r
133 +    int ret = 0;\r
134  \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
138         return 0;\r
139      }\r
140  \r
141 -    for (i = 0; i < ARRAY_SIZE (commands); i++) {\r
142 -       command = &commands[i];\r
143 -\r
144 -       if (strcmp (argv[opt_index], command->name) == 0) {\r
145 -           int ret;\r
146 -           char *talloc_report;\r
147 -\r
148 -           ret = (command->function)(local, argc - opt_index, argv + opt_index);\r
149 -\r
150 -           talloc_report = getenv ("NOTMUCH_TALLOC_REPORT");\r
151 -\r
152 -           /* this relies on the previous call to\r
153 -            * talloc_enable_null_tracking */\r
154 -\r
155 -           if (talloc_report && strcmp (talloc_report, "") != 0) {\r
156 -               FILE *report = fopen (talloc_report, "w");\r
157 -               if (report) {\r
158 -                   talloc_report_full (NULL, report);\r
159 -               } else {\r
160 -                   ret = 1;\r
161 -                   fprintf (stderr, "ERROR: unable to write talloc log. ");\r
162 -                   perror (talloc_report);\r
163 -               }\r
164 -           }\r
165 +    command = find_command (argv[opt_index]);\r
166 +    if (!command) {\r
167 +       fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",\r
168 +                argv[opt_index]);\r
169 +       return 1;\r
170 +    }\r
171  \r
172 -           return ret;\r
173 +    ret = (command->function)(local, argc - opt_index, argv + opt_index);\r
174 +\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
179 +        */\r
180 +\r
181 +       FILE *report = fopen (talloc_report, "w");\r
182 +       if (report) {\r
183 +           talloc_report_full (NULL, report);\r
184 +       } else {\r
185 +           ret = 1;\r
186 +           fprintf (stderr, "ERROR: unable to write talloc log. ");\r
187 +           perror (talloc_report);\r
188         }\r
189      }\r
190  \r
191 -    fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",\r
192 -            argv[1]);\r
193 -\r
194      talloc_free (local);\r
195  \r
196 -    return 1;\r
197 +    return ret;\r
198  }\r
199 -- \r
200 1.7.10.4\r
201 \r