Re: [PATCH] doc: Allow rst2man.py as an alternative to rst2man
[notmuch-archives.git] / 55 / 84d37497daf6ec54eb9aff0c501a835865b545
1 Return-Path: <m.walters@qmul.ac.uk>\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 C7C13431FAF\r
6         for <notmuch@notmuchmail.org>; Fri,  3 Feb 2012 15:58:58 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 rb0ZLaUef9Qu for <notmuch@notmuchmail.org>;\r
17         Fri,  3 Feb 2012 15:58:57 -0800 (PST)\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 8C6B9431FAE\r
22         for <notmuch@notmuchmail.org>; Fri,  3 Feb 2012 15:58:57 -0800 (PST)\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
24         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
25         (envelope-from <m.walters@qmul.ac.uk>)\r
26         id 1RtT1m-0000Mf-Jf; Fri, 03 Feb 2012 23:58:53 +0000\r
27 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
28         helo=localhost)\r
29         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
30         (envelope-from <m.walters@qmul.ac.uk>)\r
31         id 1RtT1m-0006p7-3C; Fri, 03 Feb 2012 23:58:50 +0000\r
32 From: Mark Walters <markwalters1009@gmail.com>\r
33 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
34 Subject: Re: [PATCH 1/2] cli: convert "notmuch show" to use the new argument\r
35         parser\r
36 In-Reply-To:\r
37  <df2e9bd7682e9c81e1b205cc1d92a1526cdd1a9b.1328308635.git.jani@nikula.org>\r
38 References:\r
39  <df2e9bd7682e9c81e1b205cc1d92a1526cdd1a9b.1328308635.git.jani@nikula.org>\r
40 User-Agent: Notmuch/0.11+129~gdd41085 (http://notmuchmail.org) Emacs/23.2.1\r
41         (i486-pc-linux-gnu)\r
42 Date: Sat, 04 Feb 2012 00:00:00 +0000\r
43 Message-ID: <87aa4zo4cf.fsf@qmul.ac.uk>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain; charset=us-ascii\r
46 X-Sender-Host-Address: 94.192.233.223\r
47 X-QM-SPAM-Info: Sender has good ham record.  :)\r
48 X-QM-Body-MD5: 1ac4dde93c63304f337a3060c40b1ce6 (of first 20000 bytes)\r
49 X-SpamAssassin-Score: -1.8\r
50 X-SpamAssassin-SpamBar: -\r
51 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
52         determine if it is\r
53         spam. We require at least 5.0 points to mark a message as spam.\r
54         This message scored -1.8 points.\r
55         Summary of the scoring: \r
56         * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
57         *      medium trust\r
58         *      [138.37.6.40 listed in list.dnswl.org]\r
59         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
60         provider *      (markwalters1009[at]gmail.com)\r
61         * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
62         *      domain\r
63         *  0.5 AWL AWL: From: address is in the auto white-list\r
64 X-QM-Scan-Virus: ClamAV says the message is clean\r
65 X-BeenThere: notmuch@notmuchmail.org\r
66 X-Mailman-Version: 2.1.13\r
67 Precedence: list\r
68 List-Id: "Use and development of the notmuch mail system."\r
69         <notmuch.notmuchmail.org>\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
73 List-Post: <mailto:notmuch@notmuchmail.org>\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
76         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
77 X-List-Received-Date: Fri, 03 Feb 2012 23:58:58 -0000\r
78 \r
79 \r
80 On Sat,  4 Feb 2012 00:41:08 +0200, Jani Nikula <jani@nikula.org> wrote:\r
81 > Use the new notmuch argument parser to handle arguments in "notmuch\r
82 > show". There are two corner case functional changes:\r
83\r
84 > 1) Also set params.raw = 1 when defaulting to raw format when part is\r
85 >    requested but format is not specified.\r
86\r
87 > 2) Do not set params.decrypt if crypto context creation fails.\r
88 \r
89 This looks great. As far as I can see it is fine (I haven't run or even\r
90 compiled it yet). I only have two query/nits below.\r
91 \r
92 Best wishes\r
93 \r
94 Mark\r
95 \r
96 > Signed-off-by: Jani Nikula <jani@nikula.org>\r
97 > ---\r
98 >  notmuch-show.c |  153 +++++++++++++++++++++++++++++---------------------------\r
99 >  1 files changed, 79 insertions(+), 74 deletions(-)\r
100\r
101 > diff --git a/notmuch-show.c b/notmuch-show.c\r
102 > index dec799c..f93e121 100644\r
103 > --- a/notmuch-show.c\r
104 > +++ b/notmuch-show.c\r
105 > @@ -1049,6 +1049,14 @@ do_show (void *ctx,\r
106 >      return 0;\r
107 >  }\r
108 >  \r
109 > +enum {\r
110 > +    NOTMUCH_FORMAT_NOT_SPECIFIED,\r
111 > +    NOTMUCH_FORMAT_JSON,\r
112 > +    NOTMUCH_FORMAT_TEXT,\r
113 > +    NOTMUCH_FORMAT_MBOX,\r
114 > +    NOTMUCH_FORMAT_RAW\r
115 > +};\r
116 > +\r
117 >  int\r
118 >  notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
119 >  {\r
120 > @@ -1056,92 +1064,98 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
121 >      notmuch_database_t *notmuch;\r
122 >      notmuch_query_t *query;\r
123 >      char *query_string;\r
124 > -    char *opt;\r
125 > +    int opt_index;\r
126 >      const notmuch_show_format_t *format = &format_text;\r
127 \r
128 I think you don't need the default value here. If you think it is\r
129 clearer with the default then that is fine. I think I slightly prefer\r
130 without since in some cases the default is raw but entirely up to you.\r
131 \r
132 > -    notmuch_show_params_t params;\r
133 > -    int mbox = 0;\r
134 > -    int format_specified = 0;\r
135 > -    int i;\r
136 > +    notmuch_show_params_t params = { .part = -1 };\r
137 \r
138 Does this initialize all the other params bits to zero/NULL?  \r
139 \r
140 \r
141 \r
142 \r
143 > +    int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;\r
144 > +    notmuch_bool_t decrypt = FALSE;\r
145 > +    notmuch_bool_t verify = FALSE;\r
146 > +    notmuch_bool_t entire_thread = FALSE;\r
147 > +\r
148 > +    notmuch_opt_desc_t options[] = {\r
149 > +     { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',\r
150 > +       (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },\r
151 > +                               { "text", NOTMUCH_FORMAT_TEXT },\r
152 > +                               { "mbox", NOTMUCH_FORMAT_MBOX },\r
153 > +                               { "raw", NOTMUCH_FORMAT_RAW },\r
154 > +                               { 0, 0 } } },\r
155 > +     { NOTMUCH_OPT_INT, &params.part, "part", 'p', 0 },\r
156 > +     { NOTMUCH_OPT_BOOLEAN, &entire_thread, "entire-thread", 't', 0 },\r
157 > +     { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },\r
158 > +     { NOTMUCH_OPT_BOOLEAN, &verify, "verify", 'v', 0 },\r
159 > +     { 0, 0, 0, 0, 0 }\r
160 > +    };\r
161 > +\r
162 > +    opt_index = parse_arguments (argc, argv, options, 1);\r
163 > +    if (opt_index < 0) {\r
164 > +     /* diagnostics already printed */\r
165 > +     return 1;\r
166 > +    }\r
167 >  \r
168 > -    params.entire_thread = 0;\r
169 > -    params.raw = 0;\r
170 > -    params.part = -1;\r
171 > -    params.cryptoctx = NULL;\r
172 > -    params.decrypt = 0;\r
173 > +    params.entire_thread = entire_thread;\r
174 >  \r
175 > -    argc--; argv++; /* skip subcommand argument */\r
176 > +    if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) {\r
177 > +     /* if part was requested and format was not specified, use format=raw */\r
178 > +     if (params.part >= 0)\r
179 > +         format_sel = NOTMUCH_FORMAT_RAW;\r
180 > +     else\r
181 > +         format_sel = NOTMUCH_FORMAT_TEXT;\r
182 > +    }\r
183 >  \r
184 > -    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
185 > -     if (strcmp (argv[i], "--") == 0) {\r
186 > -         i++;\r
187 > -         break;\r
188 > +    switch (format_sel) {\r
189 > +    case NOTMUCH_FORMAT_JSON:\r
190 > +     format = &format_json;\r
191 > +     params.entire_thread = 1;\r
192 > +     break;\r
193 > +    case NOTMUCH_FORMAT_TEXT:\r
194 > +     format = &format_text;\r
195 > +     break;\r
196 > +    case NOTMUCH_FORMAT_MBOX:\r
197 > +     if (params.part > 0) {\r
198 > +         fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n");\r
199 > +         return 1;\r
200 >       }\r
201 > -     if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
202 > -         opt = argv[i] + sizeof ("--format=") - 1;\r
203 > -         if (strcmp (opt, "text") == 0) {\r
204 > -             format = &format_text;\r
205 > -         } else if (strcmp (opt, "json") == 0) {\r
206 > -             format = &format_json;\r
207 > -             params.entire_thread = 1;\r
208 > -         } else if (strcmp (opt, "mbox") == 0) {\r
209 > -             format = &format_mbox;\r
210 > -             mbox = 1;\r
211 > -         } else if (strcmp (opt, "raw") == 0) {\r
212 > -             format = &format_raw;\r
213 > -             params.raw = 1;\r
214 > -         } else {\r
215 > -             fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
216 > -             return 1;\r
217 > -         }\r
218 > -         format_specified = 1;\r
219 > -     } else if (STRNCMP_LITERAL (argv[i], "--part=") == 0) {\r
220 > -         params.part = atoi(argv[i] + sizeof ("--part=") - 1);\r
221 > -     } else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {\r
222 > -         params.entire_thread = 1;\r
223 > -     } else if ((STRNCMP_LITERAL (argv[i], "--verify") == 0) ||\r
224 > -                (STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {\r
225 > -         if (params.cryptoctx == NULL) {\r
226 > +     format = &format_mbox;\r
227 > +     break;\r
228 > +    case NOTMUCH_FORMAT_RAW:\r
229 > +     format = &format_raw;\r
230 > +     /* If --format=raw specified without specifying part, we can only\r
231 > +      * output single message, so set part=0 */\r
232 > +     if (params.part < 0)\r
233 > +         params.part = 0;\r
234 > +     params.raw = 1;\r
235 > +     break;\r
236 > +    }\r
237 > +\r
238 > +    if (decrypt || verify) {\r
239 >  #ifdef GMIME_ATLEAST_26\r
240 > -             /* TODO: GMimePasswordRequestFunc */\r
241 > -             if (NULL == (params.cryptoctx = g_mime_gpg_context_new(NULL, "gpg")))\r
242 > +     /* TODO: GMimePasswordRequestFunc */\r
243 > +     params.cryptoctx = g_mime_gpg_context_new (NULL, "gpg");\r
244 >  #else\r
245 > -             GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);\r
246 > -             if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg")))\r
247 > -#endif\r
248 > -                 fprintf (stderr, "Failed to construct gpg context.\n");\r
249 > -             else\r
250 > -                 g_mime_gpg_context_set_always_trust((GMimeGpgContext*)params.cryptoctx, FALSE);\r
251 > -#ifndef GMIME_ATLEAST_26\r
252 > -             g_object_unref (session);\r
253 > -             session = NULL;\r
254 > +     GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
255 > +     params.cryptoctx = g_mime_gpg_context_new (session, "gpg");\r
256 >  #endif\r
257 > -         }\r
258 > -         if (STRNCMP_LITERAL (argv[i], "--decrypt") == 0)\r
259 > -             params.decrypt = 1;\r
260 > +     if (params.cryptoctx) {\r
261 > +         g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);\r
262 > +         params.decrypt = decrypt;\r
263 >       } else {\r
264 > -         fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
265 > -         return 1;\r
266 > +         fprintf (stderr, "Failed to construct gpg context.\n");\r
267 >       }\r
268 > +#ifndef GMIME_ATLEAST_26\r
269 > +     g_object_unref (session);\r
270 > +#endif\r
271 >      }\r
272 >  \r
273 > -    argc -= i;\r
274 > -    argv += i;\r
275 > -\r
276 >      config = notmuch_config_open (ctx, NULL, NULL);\r
277 >      if (config == NULL)\r
278 >       return 1;\r
279 >  \r
280 > -    query_string = query_string_from_args (ctx, argc, argv);\r
281 > +    query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);\r
282 >      if (query_string == NULL) {\r
283 >       fprintf (stderr, "Out of memory\n");\r
284 >       return 1;\r
285 >      }\r
286 >  \r
287 > -    if (mbox && params.part > 0) {\r
288 > -     fprintf (stderr, "Error: specifying parts is incompatible with mbox output format.\n");\r
289 > -     return 1;\r
290 > -    }\r
291 > -\r
292 >      if (*query_string == '\0') {\r
293 >       fprintf (stderr, "Error: notmuch show requires at least one search term.\n");\r
294 >       return 1;\r
295 > @@ -1158,15 +1172,6 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
296 >       return 1;\r
297 >      }\r
298 >  \r
299 > -    /* if part was requested and format was not specified, use format=raw */\r
300 > -    if (params.part >= 0 && !format_specified)\r
301 > -     format = &format_raw;\r
302 > -\r
303 > -    /* If --format=raw specified without specifying part, we can only\r
304 > -     * output single message, so set part=0 */\r
305 > -    if (params.raw && params.part < 0)\r
306 > -     params.part = 0;\r
307 > -\r
308 >      if (params.part >= 0)\r
309 >       return do_show_single (ctx, query, format, &params);\r
310 >      else\r
311 > -- \r
312 > 1.7.5.4\r
313\r
314 > _______________________________________________\r
315 > notmuch mailing list\r
316 > notmuch@notmuchmail.org\r
317 > http://notmuchmail.org/mailman/listinfo/notmuch\r