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
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
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
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
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
50 Unfortunately it seems trickier to support --config globally
\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
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
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
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
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 *) ¬much_shared_options, NULL, 0, 0 },
\r
92 opt_index = parse_arguments (argc, argv, options, 1);
\r
94 return EXIT_FAILURE;
\r
96 + notmuch_process_shared_options (argv[0]);
\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
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 *) ¬much_shared_options, NULL, 0, 0 },
\r
113 @@ -153,6 +154,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])
\r
115 return EXIT_FAILURE;
\r
117 + notmuch_process_shared_options (argv[0]);
\r
119 if (input_file_name) {
\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
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 *) ¬much_shared_options, NULL, 0, 0 },
\r
134 @@ -235,6 +236,8 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])
\r
136 return EXIT_FAILURE;
\r
138 + notmuch_process_shared_options (argv[0]);
\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 *) ¬much_shared_options, NULL, 0, 0 },
\r
152 { NOTMUCH_OPT_END, 0, 0, 0, 0 }
\r
155 @@ -473,6 +474,8 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
\r
157 return EXIT_FAILURE;
\r
159 + notmuch_process_shared_options (argv[0]);
\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 *) ¬much_shared_options, NULL, 0, 0 },
\r
176 @@ -941,6 +942,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
\r
178 return EXIT_FAILURE;
\r
180 + notmuch_process_shared_options (argv[0]);
\r
182 /* quiet trumps verbose */
\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
192 { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 },
\r
193 + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
\r
197 @@ -797,6 +798,8 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
\r
199 return EXIT_FAILURE;
\r
201 + notmuch_process_shared_options (argv[0]);
\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
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 *) ¬much_shared_options, NULL, 0, 0 },
\r
218 @@ -163,6 +164,7 @@ notmuch_restore_command (notmuch_config_t *config, int argc, char *argv[])
\r
222 + notmuch_process_shared_options (argv[0]);
\r
223 name_for_error = input_file_name ? input_file_name : "stdin";
\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 *) ¬much_shared_options, NULL, 0, 0 },
\r
238 @@ -689,6 +690,8 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])
\r
240 return EXIT_FAILURE;
\r
242 + notmuch_process_shared_options (argv[0]);
\r
244 if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES &&
\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
250 { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 },
\r
251 + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
\r
255 @@ -744,6 +748,8 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])
\r
257 return EXIT_FAILURE;
\r
259 + notmuch_process_shared_options (argv[0]);
\r
261 if (! (ctx->output & (OUTPUT_SENDER | OUTPUT_RECIPIENTS)))
\r
262 ctx->output |= OUTPUT_SENDER;
\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, ¶ms.crypto.verify, "verify", 'v', 0 },
\r
270 { NOTMUCH_OPT_BOOLEAN, ¶ms.output_body, "body", 'b', 0 },
\r
271 { NOTMUCH_OPT_BOOLEAN, ¶ms.include_html, "include-html", 0, 0 },
\r
272 + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
\r
276 @@ -1121,6 +1122,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
\r
278 return EXIT_FAILURE;
\r
280 + notmuch_process_shared_options (argv[0]);
\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 *) ¬much_shared_options, NULL, 0, 0 },
\r
297 @@ -213,6 +214,8 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])
\r
299 return EXIT_FAILURE;
\r
301 + notmuch_process_shared_options (argv[0]);
\r
303 if (input_file_name) {
\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
310 @@ -43,6 +43,35 @@ notmuch_help_command (notmuch_config_t *config, int argc, char *argv[]);
\r
312 notmuch_command (notmuch_config_t *config, int argc, char *argv[]);
\r
315 +_help_for (const char *topic);
\r
317 +static notmuch_bool_t print_version = FALSE, print_help = FALSE;
\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
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
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
336 + if (print_help) {
\r
337 + int ret = _help_for (subcommand_name);
\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
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 *) ¬much_shared_options, NULL, 0, 0 },
\r
362 @@ -324,24 +351,7 @@ main (int argc, char *argv[])
\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
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
374 - ret = notmuch_help_command (NULL, argc - opt_index + 1,
\r
375 - argv + opt_index - 1);
\r
379 - if (print_version) {
\r
380 - printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n");
\r
381 - ret = EXIT_SUCCESS;
\r
384 + notmuch_process_shared_options (NULL);
\r
386 if (opt_index < argc)
\r
387 command_name = argv[opt_index];
\r