Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / fa / 47d7d059cf5b0fe520b531edfdc1fe820ee06c
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 86AC76DE1B4C\r
6  for <notmuch@notmuchmail.org>; Sun,  5 Apr 2015 14:33:58 -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.643\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.643 tagged_above=-999 required=5 tests=[AWL=0.633, \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 GVvURo72waot for <notmuch@notmuchmail.org>;\r
16  Sun,  5 Apr 2015 14:33:56 -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 A2F296DE1B43\r
20  for <notmuch@notmuchmail.org>; Sun,  5 Apr 2015 14:33:56 -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 1Yerg0-0002S4-6R; Sun, 05 Apr 2015 21:01:52 +0000\r
24 Received: (nullmailer pid 29564 invoked by uid 1000); Sun, 05 Apr 2015\r
25  21:00:40 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 3/4] cli: define shared options, use for --help and --version\r
29 Date: Mon,  6 Apr 2015 05:59:33 +0900\r
30 Message-Id: <1428267574-28797-4-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.1.4\r
32 In-Reply-To: <1428267574-28797-1-git-send-email-david@tethera.net>\r
33 References: <1428267574-28797-1-git-send-email-david@tethera.net>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.18\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Sun, 05 Apr 2015 21:33:58 -0000\r
47 \r
48 Unfortunately it seems trickier to support --config globally\r
49 ---\r
50  notmuch-client.h  |  2 ++\r
51  notmuch-compact.c |  4 ++++\r
52  notmuch-count.c   |  3 +++\r
53  notmuch-dump.c    |  3 +++\r
54  notmuch-insert.c  |  3 +++\r
55  notmuch-new.c     |  3 +++\r
56  notmuch-reply.c   |  3 +++\r
57  notmuch-search.c  |  3 +++\r
58  notmuch-show.c    |  3 +++\r
59  notmuch-tag.c     |  3 +++\r
60  notmuch.c         | 52 +++++++++++++++++++++++++++++++---------------------\r
61  11 files changed, 61 insertions(+), 21 deletions(-)\r
62 \r
63 diff --git a/notmuch-client.h b/notmuch-client.h\r
64 index fb3021c..ab0d188 100644\r
65 --- a/notmuch-client.h\r
66 +++ b/notmuch-client.h\r
67 @@ -466,4 +466,6 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
68                        notmuch_bool_t gzip_output);\r
69  \r
70  #include "command-line-arguments.h"\r
71 +extern const notmuch_opt_desc_t  notmuch_shared_options [];\r
72 +void notmuch_process_shared_options (const char* help_name);\r
73  #endif\r
74 diff --git a/notmuch-compact.c b/notmuch-compact.c\r
75 index 2fc012a..5be551d 100644\r
76 --- a/notmuch-compact.c\r
77 +++ b/notmuch-compact.c\r
78 @@ -38,12 +38,16 @@ notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[])\r
79      notmuch_opt_desc_t options[] = {\r
80         { NOTMUCH_OPT_STRING, &backup_path, "backup", 0, 0 },\r
81         { NOTMUCH_OPT_BOOLEAN,  &quiet, "quiet", 'q', 0 },\r
82 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
83 +       { 0, 0, 0, 0, 0}\r
84      };\r
85  \r
86      opt_index = parse_arguments (argc, argv, options, 1);\r
87      if (opt_index < 0)\r
88         return EXIT_FAILURE;\r
89  \r
90 +    notmuch_process_shared_options (argv[0]);\r
91 +\r
92      if (! quiet)\r
93         printf ("Compacting database...\n");\r
94      ret = notmuch_database_compact (path, backup_path,\r
95 diff --git a/notmuch-count.c b/notmuch-count.c\r
96 index 6058f7c..57a88a8 100644\r
97 --- a/notmuch-count.c\r
98 +++ b/notmuch-count.c\r
99 @@ -146,6 +146,7 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
100                                   { 0, 0 } } },\r
101         { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
102         { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
103 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
104         { 0, 0, 0, 0, 0 }\r
105      };\r
106  \r
107 @@ -153,6 +154,8 @@ notmuch_count_command (notmuch_config_t *config, int argc, char *argv[])\r
108      if (opt_index < 0)\r
109         return EXIT_FAILURE;\r
110  \r
111 +    notmuch_process_shared_options (argv[0]);\r
112 +\r
113      if (input_file_name) {\r
114         batch = TRUE;\r
115         input = fopen (input_file_name, "r");\r
116 diff --git a/notmuch-dump.c b/notmuch-dump.c\r
117 index 9c6ad7f..fab22bd 100644\r
118 --- a/notmuch-dump.c\r
119 +++ b/notmuch-dump.c\r
120 @@ -228,6 +228,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
121                                   { 0, 0 } } },\r
122         { NOTMUCH_OPT_STRING, &output_file_name, "output", 'o', 0  },\r
123         { NOTMUCH_OPT_BOOLEAN, &gzip_output, "gzip", 'z', 0 },\r
124 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
125         { 0, 0, 0, 0, 0 }\r
126      };\r
127  \r
128 @@ -235,6 +236,8 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[])\r
129      if (opt_index < 0)\r
130         return EXIT_FAILURE;\r
131  \r
132 +    notmuch_process_shared_options (argv[0]);\r
133 +\r
134      if (opt_index < argc) {\r
135         query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);\r
136         if (query_str == NULL) {\r
137 diff --git a/notmuch-insert.c b/notmuch-insert.c\r
138 index 90fe3ba..697880f 100644\r
139 --- a/notmuch-insert.c\r
140 +++ b/notmuch-insert.c\r
141 @@ -466,6 +466,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
142         { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },\r
143         { NOTMUCH_OPT_BOOLEAN, &keep, "keep", 0, 0 },\r
144         { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },\r
145 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
146         { NOTMUCH_OPT_END, 0, 0, 0, 0 }\r
147      };\r
148  \r
149 @@ -473,6 +474,8 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
150      if (opt_index < 0)\r
151         return EXIT_FAILURE;\r
152  \r
153 +    notmuch_process_shared_options (argv[0]);\r
154 +\r
155      db_path = notmuch_config_get_database_path (config);\r
156      new_tags = notmuch_config_get_new_tags (config, &new_tags_length);\r
157      synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
158 diff --git a/notmuch-new.c b/notmuch-new.c\r
159 index e6c283e..895f5d9 100644\r
160 --- a/notmuch-new.c\r
161 +++ b/notmuch-new.c\r
162 @@ -934,6 +934,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
163         { NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },\r
164         { NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },\r
165         { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },\r
166 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
167         { 0, 0, 0, 0, 0 }\r
168      };\r
169  \r
170 @@ -941,6 +942,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
171      if (opt_index < 0)\r
172         return EXIT_FAILURE;\r
173  \r
174 +    notmuch_process_shared_options (argv[0]);\r
175 +\r
176      /* quiet trumps verbose */\r
177      if (quiet)\r
178         add_files_state.verbosity = VERBOSITY_QUIET;\r
179 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
180 index d51fdfc..4464741 100644\r
181 --- a/notmuch-reply.c\r
182 +++ b/notmuch-reply.c\r
183 @@ -790,6 +790,7 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
184                                   { "sender", FALSE },\r
185                                   { 0, 0 } } },\r
186         { NOTMUCH_OPT_BOOLEAN, &params.crypto.decrypt, "decrypt", 'd', 0 },\r
187 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
188         { 0, 0, 0, 0, 0 }\r
189      };\r
190  \r
191 @@ -797,6 +798,8 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])\r
192      if (opt_index < 0)\r
193         return EXIT_FAILURE;\r
194  \r
195 +    notmuch_process_shared_options (argv[0]);\r
196 +\r
197      if (format == FORMAT_HEADERS_ONLY) {\r
198         reply_format_func = notmuch_reply_format_headers_only;\r
199      } else if (format == FORMAT_JSON) {\r
200 diff --git a/notmuch-search.c b/notmuch-search.c\r
201 index b81ac01..994ae58 100644\r
202 --- a/notmuch-search.c\r
203 +++ b/notmuch-search.c\r
204 @@ -681,6 +681,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
205         { NOTMUCH_OPT_INT, &ctx->limit, "limit", 'L', 0  },\r
206         { NOTMUCH_OPT_INT, &ctx->dupe, "duplicate", 'D', 0  },\r
207         { NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 },\r
208 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
209         { 0, 0, 0, 0, 0 }\r
210      };\r
211  \r
212 @@ -689,6 +690,8 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
213      if (opt_index < 0)\r
214         return EXIT_FAILURE;\r
215  \r
216 +    notmuch_process_shared_options (argv[0]);\r
217 +\r
218      if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES &&\r
219         ctx->dupe != -1) {\r
220          fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n");\r
221 diff --git a/notmuch-show.c b/notmuch-show.c\r
222 index 43bf71c..b80933a 100644\r
223 --- a/notmuch-show.c\r
224 +++ b/notmuch-show.c\r
225 @@ -1114,6 +1114,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
226         { NOTMUCH_OPT_BOOLEAN, &params.crypto.verify, "verify", 'v', 0 },\r
227         { NOTMUCH_OPT_BOOLEAN, &params.output_body, "body", 'b', 0 },\r
228         { NOTMUCH_OPT_BOOLEAN, &params.include_html, "include-html", 0, 0 },\r
229 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
230         { 0, 0, 0, 0, 0 }\r
231      };\r
232  \r
233 @@ -1121,6 +1122,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])\r
234      if (opt_index < 0)\r
235         return EXIT_FAILURE;\r
236  \r
237 +    notmuch_process_shared_options (argv[0]);\r
238 +\r
239      /* decryption implies verification */\r
240      if (params.crypto.decrypt)\r
241         params.crypto.verify = TRUE;\r
242 diff --git a/notmuch-tag.c b/notmuch-tag.c\r
243 index 5b2f1e4..35f971d 100644\r
244 --- a/notmuch-tag.c\r
245 +++ b/notmuch-tag.c\r
246 @@ -206,6 +206,7 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
247         { NOTMUCH_OPT_BOOLEAN, &batch, "batch", 0, 0 },\r
248         { NOTMUCH_OPT_STRING, &input_file_name, "input", 'i', 0 },\r
249         { NOTMUCH_OPT_BOOLEAN, &remove_all, "remove-all", 0, 0 },\r
250 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
251         { 0, 0, 0, 0, 0 }\r
252      };\r
253  \r
254 @@ -213,6 +214,8 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[])\r
255      if (opt_index < 0)\r
256         return EXIT_FAILURE;\r
257  \r
258 +    notmuch_process_shared_options (argv[0]);\r
259 +\r
260      if (input_file_name) {\r
261         batch = TRUE;\r
262         input = fopen (input_file_name, "r");\r
263 diff --git a/notmuch.c b/notmuch.c\r
264 index bff941f..c7f8c8f 100644\r
265 --- a/notmuch.c\r
266 +++ b/notmuch.c\r
267 @@ -43,6 +43,35 @@ notmuch_help_command (notmuch_config_t *config, int argc, char *argv[]);\r
268  static int\r
269  notmuch_command (notmuch_config_t *config, int argc, char *argv[]);\r
270  \r
271 +static int\r
272 +_help_for (const char *topic);\r
273 +\r
274 +static notmuch_bool_t print_version = FALSE, print_help = FALSE;\r
275 +\r
276 +const notmuch_opt_desc_t notmuch_shared_options [] = {\r
277 +    { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },\r
278 +    { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },\r
279 +    {0, 0, 0, 0, 0}\r
280 +};\r
281 +\r
282 +/* any subcommand wanting to support these options should call\r
283 + * inherit notmuch_shared_options and call\r
284 + * notmuch_process_shared_options (subcommand_name);\r
285 + */\r
286 +void\r
287 +notmuch_process_shared_options (const char *help_name) {\r
288 +    if (print_version) {\r
289 +       printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n");\r
290 +       exit (EXIT_SUCCESS);\r
291 +    }\r
292 +\r
293 +    if (print_help) {\r
294 +       int ret = _help_for (help_name);\r
295 +       exit (ret);\r
296 +    }\r
297 +}\r
298 +\r
299 +\r
300  static command_t commands[] = {\r
301      { NULL, notmuch_command, TRUE,\r
302        "Notmuch main command." },\r
303 @@ -295,14 +324,12 @@ main (int argc, char *argv[])\r
304      command_t *command;\r
305      char *config_file_name = NULL;\r
306      notmuch_config_t *config = NULL;\r
307 -    notmuch_bool_t print_help=FALSE, print_version=FALSE;\r
308      int opt_index;\r
309      int ret;\r
310  \r
311      notmuch_opt_desc_t options[] = {\r
312 -       { NOTMUCH_OPT_BOOLEAN, &print_help, "help", 'h', 0 },\r
313 -       { NOTMUCH_OPT_BOOLEAN, &print_version, "version", 'v', 0 },\r
314         { NOTMUCH_OPT_STRING, &config_file_name, "config", 'c', 0 },\r
315 +       { NOTMUCH_OPT_INHERIT, (void *) &notmuch_shared_options, NULL, 0, 0 },\r
316         { 0, 0, 0, 0, 0 }\r
317      };\r
318  \r
319 @@ -324,24 +351,7 @@ main (int argc, char *argv[])\r
320         goto DONE;\r
321      }\r
322  \r
323 -    /* Handle notmuch --help [command] and notmuch command --help. */\r
324 -    if (print_help ||\r
325 -       (opt_index + 1 < argc && strcmp (argv[opt_index + 1], "--help") == 0)) {\r
326 -       /*\r
327 -        * Pass the first positional argument as argv[1] so the help\r
328 -        * command can give help for it. The help command ignores the\r
329 -        * argv[0] passed to it.\r
330 -        */\r
331 -       ret = notmuch_help_command (NULL, argc - opt_index + 1,\r
332 -                                   argv + opt_index - 1);\r
333 -       goto DONE;\r
334 -    }\r
335 -\r
336 -    if (print_version) {\r
337 -       printf ("notmuch " STRINGIFY(NOTMUCH_VERSION) "\n");\r
338 -       ret = EXIT_SUCCESS;\r
339 -       goto DONE;\r
340 -    }\r
341 +    notmuch_process_shared_options (NULL);\r
342  \r
343      if (opt_index < argc)\r
344         command_name = argv[opt_index];\r
345 -- \r
346 2.1.4\r
347 \r