[PATCH] configure: add --without-api-docs option
[notmuch-archives.git] / c4 / c7ec8c8f60dd54736ab7fa83f18538b402e008
1 Return-Path: <bremner@tesseract.cs.unb.ca>\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 8D3CD6DE1AEF\r
6  for <notmuch@notmuchmail.org>; Tue,  7 Apr 2015 12:33:23 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.424\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.424 tagged_above=-999 required=5 tests=[AWL=0.414, \r
12  T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id JLYqZMON8xGW for <notmuch@notmuchmail.org>;\r
16  Tue,  7 Apr 2015 12:33:21 -0700 (PDT)\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
18  [87.98.215.224])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id A1B8F6DE1AE3\r
20  for <notmuch@notmuchmail.org>; Tue,  7 Apr 2015 12:33:21 -0700 (PDT)\r
21 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
22  4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
23  id 1YfZDr-0001y1-LH; Tue, 07 Apr 2015 19:31:43 +0000\r
24 Received: (nullmailer pid 16654 invoked by uid 1000); Tue, 07 Apr 2015\r
25  19:30:50 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: Mark Walters <markwalters1009@gmail.com>, David Bremner\r
28  <david@tethera.net>, notmuch@notmuchmail.org\r
29 Subject: [PATCH 3/4] cli: define shared options, use for --help and --version\r
30 Date: Wed,  8 Apr 2015 04:30:41 +0900\r
31 Message-Id: <1428435042-16503-4-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 2.1.4\r
33 In-Reply-To: <1428435042-16503-1-git-send-email-david@tethera.net>\r
34 References: <871tjws8w8.fsf@qmul.ac.uk>\r
35  <1428435042-16503-1-git-send-email-david@tethera.net>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.18\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40  <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Tue, 07 Apr 2015 19:33:23 -0000\r
49 \r
50 Unfortunately it seems trickier to support --config globally\r
51 \r
52 The non-trivial changes are in notmuch.c; most of the other changes\r
53 consists of blindly inserting two lines into every subcommand.\r
54 ---\r
55  notmuch-client.h  |  2 ++\r
56  notmuch-compact.c |  4 ++++\r
57  notmuch-count.c   |  3 +++\r
58  notmuch-dump.c    |  3 +++\r
59  notmuch-insert.c  |  3 +++\r
60  notmuch-new.c     |  3 +++\r
61  notmuch-reply.c   |  3 +++\r
62  notmuch-restore.c |  2 ++\r
63  notmuch-search.c  |  6 ++++++\r
64  notmuch-show.c    |  3 +++\r
65  notmuch-tag.c     |  3 +++\r
66  notmuch.c         | 52 +++++++++++++++++++++++++++++++---------------------\r
67  12 files changed, 66 insertions(+), 21 deletions(-)\r
68 \r
69 diff --git a/notmuch-client.h b/notmuch-client.h\r
70 index fb3021c..8ecfac6 100644\r
71 --- a/notmuch-client.h\r
72 +++ b/notmuch-client.h\r
73 @@ -466,4 +466,6 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
74                        notmuch_bool_t gzip_output);\r
75  \r
76  #include "command-line-arguments.h"\r
77 +extern const notmuch_opt_desc_t  notmuch_shared_options [];\r
78 +void notmuch_process_shared_options (const char* subcommand_name);\r
79  #endif\r
80 diff --git a/notmuch-compact.c b/notmuch-compact.c\r
81 index 2fc012a..5be551d 100644\r
82 --- a/notmuch-compact.c\r
83 +++ b/notmuch-compact.c\r
84 @@ -38,12 +38,16 @@ notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[])\r
85      notmuch_opt_desc_t options[] = {\r
86         { NOTMUCH_OPT_STRING, &backup_path, "backup", 0, 0 },\r
87         { NOTMUCH_OPT_BOOLEAN,  &quiet, "quiet", 'q', 0 },\r
88 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
89 +       { 0, 0, 0, 0, 0}\r
90      };\r
91  \r
92      opt_index = parse_arguments (argc, argv, options, 1);\r
93      if (opt_index < 0)\r
94         return EXIT_FAILURE;\r
95  \r
96 +    notmuch_process_shared_options (argv[0]);\r
97 +\r
98      if (! quiet)\r
99         printf ("Compacting database...\n");\r
100      ret = notmuch_database_compact (path, backup_path,\r
101 diff --git a/notmuch-count.c b/notmuch-count.c\r
102 index 6058f7c..57a88a8 100644\r
103 --- a/notmuch-count.c\r
104 +++ b/notmuch-count.c\r
105 @@ -146,6 +146,7 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
106                                   { 0, 0 } } },\r
107         { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
108         { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
109 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
110         { 0, 0, 0, 0, 0 }\r
111      };\r
112  \r
113 @@ -153,6 +154,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
114      if (opt_index < 0)\r
115         return EXIT_FAILURE;\r
116  \r
117 +    notmuch_process_shared_options (argv[0]);\r
118 +\r
119      if (input_file_name) {\r
120         batch = TRUE;\r
121         input = fopen (input_file_name, "r");\r
122 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
123 index 9c6ad7f..fab22bd 100644\r
124 --- a/notmuch-dump.c\r
125 +++ b/notmuch-dump.c\r
126 @@ -228,6 +228,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
127                                   { 0, 0 } } },\r
128         { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0  },\r
129         { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },\r
130 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
131         { 0, 0, 0, 0, 0 }\r
132      };\r
133  \r
134 @@ -235,6 +236,8 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
135      if (opt_index < 0)\r
136         return EXIT_FAILURE;\r
137  \r
138 +    notmuch_process_shared_options (argv[0]);\r
139 +\r
140      if (opt_index < argc) {\r
141         query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);\r
142         if (query_str == NULL) {\r
143 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
144 index 90fe3ba..697880f 100644\r
145 --- a/notmuch-insert.c\r
146 +++ b/notmuch-insert.c\r
147 @@ -466,6 +466,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
148         { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },\r
149         { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },\r
150         { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },\r
151 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
152         { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
153      };\r
154  \r
155 @@ -473,6 +474,8 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
156      if (opt_index < 0)\r
157         return EXIT_FAILURE;\r
158  \r
159 +    notmuch_process_shared_options (argv[0]);\r
160 +\r
161      db_path = notmuch_config_get_database_path (config);\r
162      new_tags = notmuch_config_get_new_tags (config, &new_tags_length);\r
163      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
164 diff --git a/notmuch-new.c b/notmuch-new.c\r
165 index e6c283e..895f5d9 100644\r
166 --- a/notmuch-new.c\r
167 +++ b/notmuch-new.c\r
168 @@ -934,6 +934,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
169         { NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },\r
170         { NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },\r
171         { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },\r
172 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
173         { 0, 0, 0, 0, 0 }\r
174      };\r
175  \r
176 @@ -941,6 +942,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
177      if (opt_index < 0)\r
178         return EXIT_FAILURE;\r
179  \r
180 +    notmuch_process_shared_options (argv[0]);\r
181 +\r
182      /* quiet trumps verbose */\r
183      if (quiet)\r
184         add_files_state.verbosity = VERBOSITY_QUIET;\r
185 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
186 index d51fdfc..4464741 100644\r
187 --- a/notmuch-reply.c\r
188 +++ b/notmuch-reply.c\r
189 @@ -790,6 +790,7 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
190                                   { "sender", FALSE },\r
191                                   { 0, 0 } } },\r
192         { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },\r
193 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
194         { 0, 0, 0, 0, 0 }\r
195      };\r
196  \r
197 @@ -797,6 +798,8 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
198      if (opt_index < 0)\r
199         return EXIT_FAILURE;\r
200  \r
201 +    notmuch_process_shared_options (argv[0]);\r
202 +\r
203      if (format == FORMAT_HEADERS_ONLY) {\r
204         reply_format_func = notmuch_reply_format_headers_only;\r
205      } else if (format == FORMAT_JSON) {\r
206 diff --git a/notmuch-restore.c b/notmuch-restore.c\r
207 index 584d9f9..2a534dc 100644\r
208 --- a/notmuch-restore.c\r
209 +++ b/notmuch-restore.c\r
210 @@ -154,6 +154,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
211                                   { 0, 0 } } },\r
212         { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
213         { NOTMUCH_OPT_BOOLEAN,  &accumulate, "accumulate", 'a', 0 },\r
214 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
215         { 0, 0, 0, 0, 0 }\r
216      };\r
217  \r
218 @@ -163,6 +164,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])\r
219         goto DONE;\r
220      }\r
221  \r
222 +    notmuch_process_shared_options (argv[0]);\r
223      name_for_error = input_file_name ? input_file_name : "stdin";\r
224  \r
225      if (! accumulate)\r
226 diff --git a/notmuch-search.c b/notmuch-search.c\r
227 index b81ac01..b89a17e 100644\r
228 --- a/notmuch-search.c\r
229 +++ b/notmuch-search.c\r
230 @@ -681,6 +681,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
231         { NOTMUCH_OPT_INT, &ctx->limit, "limit", 'L', 0  },\r
232         { NOTMUCH_OPT_INT, &ctx->dupe, "duplicate", 'D', 0  },\r
233         { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 },\r
234 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
235         { 0, 0, 0, 0, 0 }\r
236      };\r
237  \r
238 @@ -689,6 +690,8 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
239      if (opt_index < 0)\r
240         return EXIT_FAILURE;\r
241  \r
242 +    notmuch_process_shared_options (argv[0]);\r
243 +\r
244      if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES &&\r
245         ctx->dupe != -1) {\r
246          fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");\r
247 @@ -737,6 +740,7 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])\r
248                                   { "false", NOTMUCH_EXCLUDE_FALSE },\r
249                                   { 0, 0 } } },\r
250         { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 },\r
251 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
252         { 0, 0, 0, 0, 0 }\r
253      };\r
254  \r
255 @@ -744,6 +748,8 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])\r
256      if (opt_index < 0)\r
257         return EXIT_FAILURE;\r
258  \r
259 +    notmuch_process_shared_options (argv[0]);\r
260 +\r
261      if (! (ctx->output & (OUTPUT_SENDER | OUTPUT_RECIPIENTS)))\r
262         ctx->output |= OUTPUT_SENDER;\r
263  \r
264 diff --git a/notmuch-show.c b/notmuch-show.c\r
265 index 43bf71c..b80933a 100644\r
266 --- a/notmuch-show.c\r
267 +++ b/notmuch-show.c\r
268 @@ -1114,6 +1114,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
269         { NOTMUCH_OPT_BOOLEAN, &params.crypto.verify, "verify", 'v', 0 },\r
270         { NOTMUCH_OPT_BOOLEAN, &params.output_body, "body", 'b', 0 },\r
271         { NOTMUCH_OPT_BOOLEAN, &params.include_html, "include-html", 0, 0 },\r
272 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
273         { 0, 0, 0, 0, 0 }\r
274      };\r
275  \r
276 @@ -1121,6 +1122,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
277      if (opt_index < 0)\r
278         return EXIT_FAILURE;\r
279  \r
280 +    notmuch_process_shared_options (argv[0]);\r
281 +\r
282      /* decryption implies verification */\r
283      if (params.crypto.decrypt)\r
284         params.crypto.verify = TRUE;\r
285 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
286 index 5b2f1e4..35f971d 100644\r
287 --- a/notmuch-tag.c\r
288 +++ b/notmuch-tag.c\r
289 @@ -206,6 +206,7 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
290         { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
291         { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
292         { NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 },\r
293 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
294         { 0, 0, 0, 0, 0 }\r
295      };\r
296  \r
297 @@ -213,6 +214,8 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
298      if (opt_index < 0)\r
299         return EXIT_FAILURE;\r
300  \r
301 +    notmuch_process_shared_options (argv[0]);\r
302 +\r
303      if (input_file_name) {\r
304         batch = TRUE;\r
305         input = fopen (input_file_name, "r");\r
306 diff --git a/notmuch.c b/notmuch.c\r
307 index bff941f..3a9da90 100644\r
308 --- a/notmuch.c\r
309 +++ b/notmuch.c\r
310 @@ -43,6 +43,35 @@ notmuch_help_command (notmuch_config_t *config, int argc, char *argv[]);\r
311  static int\r
312  notmuch_command (notmuch_config_t *config, int argc, char *argv[]);\r
313  \r
314 +static int\r
315 +_help_for (const char *topic);\r
316 +\r
317 +static notmuch_bool_t print_version = FALSE, print_help = FALSE;\r
318 +\r
319 +const notmuch_opt_desc_t notmuch_shared_options [] = {\r
320 +    { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },\r
321 +    { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },\r
322 +    {0, 0, 0, 0, 0}\r
323 +};\r
324 +\r
325 +/* any subcommand wanting to support these options should call\r
326 + * inherit notmuch_shared_options and call\r
327 + * notmuch_process_shared_options (subcommand_name);\r
328 + */\r
329 +void\r
330 +notmuch_process_shared_options (const char *subcommand_name) {\r
331 +    if (print_version) {\r
332 +       printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n");\r
333 +       exit (EXIT_SUCCESS);\r
334 +    }\r
335 +\r
336 +    if (print_help) {\r
337 +       int ret = _help_for (subcommand_name);\r
338 +       exit (ret);\r
339 +    }\r
340 +}\r
341 +\r
342 +\r
343  static command_t commands[] = {\r
344      { NULL, notmuch_command, TRUE,\r
345        "Notmuch main command." },\r
346 @@ -295,14 +324,12 @@ main (int argc, char *argv[])\r
347      command_t *command;\r
348      char *config_file_name = NULL;\r
349      notmuch_config_t *config = NULL;\r
350 -    notmuch_bool_t print_help=FALSE, print_version=FALSE;\r
351      int opt_index;\r
352      int ret;\r
353  \r
354      notmuch_opt_desc_t options[] = {\r
355 -       { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },\r
356 -       { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },\r
357         { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 },\r
358 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
359         { 0, 0, 0, 0, 0 }\r
360      };\r
361  \r
362 @@ -324,24 +351,7 @@ main (int argc, char *argv[])\r
363         goto DONE;\r
364      }\r
365  \r
366 -    /* Handle notmuch --help [command] and notmuch command --help. */\r
367 -    if (print_help ||\r
368 -       (opt_index + 1 < argc && strcmp (argv[opt_index + 1], "--help") == 0)) {\r
369 -       /*\r
370 -        * Pass the first positional argument as argv[1] so the help\r
371 -        * command can give help for it. The help command ignores the\r
372 -        * argv[0] passed to it.\r
373 -        */\r
374 -       ret = notmuch_help_command (NULL, argc - opt_index + 1,\r
375 -                                   argv + opt_index - 1);\r
376 -       goto DONE;\r
377 -    }\r
378 -\r
379 -    if (print_version) {\r
380 -       printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n");\r
381 -       ret = EXIT_SUCCESS;\r
382 -       goto DONE;\r
383 -    }\r
384 +    notmuch_process_shared_options (NULL);\r
385  \r
386      if (opt_index < argc)\r
387         command_name = argv[opt_index];\r
388 -- \r
389 2.1.4\r
390 \r