Re: [PATCH v4 13/16] add indexopts to notmuch python bindings.
[notmuch-archives.git] / 63 / ba8def433dbd195017b0d78380e7a7de325d26
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 14AAD42116D\r
6         for <notmuch@notmuchmail.org>; Thu,  5 Jan 2012 12:25:29 -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 jMxWmehpqxhb for <notmuch@notmuchmail.org>;\r
17         Thu,  5 Jan 2012 12:25:27 -0800 (PST)\r
18 Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
19  [74.125.83.53])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
20  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
21  2275F429E3B    for <notmuch@notmuchmail.org>; Thu,  5 Jan 2012 12:25:27 -0800\r
22  (PST)\r
23 Received: by mail-ee0-f53.google.com with SMTP id d41so756745eek.26\r
24         for <notmuch@notmuchmail.org>; Thu, 05 Jan 2012 12:25:26 -0800 (PST)\r
25 Received: by 10.14.22.10 with SMTP id s10mr1232481ees.122.1325795126730;\r
26         Thu, 05 Jan 2012 12:25:26 -0800 (PST)\r
27 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
28         [80.220.92.23])\r
29         by mx.google.com with ESMTPS id s16sm238060005eef.2.2012.01.05.12.25.24\r
30         (version=SSLv3 cipher=OTHER); Thu, 05 Jan 2012 12:25:25 -0800 (PST)\r
31 From: Jani Nikula <jani@nikula.org>\r
32 To: notmuch@notmuchmail.org,\r
33         david@tethera.net\r
34 Subject: [PATCH 2/4] cli: convert "notmuch reply" to use the new argument\r
35         parser\r
36 Date: Thu,  5 Jan 2012 22:25:13 +0200\r
37 Message-Id:\r
38  <74f31cf0b3dc11b365a3838a44f095326d6c9f99.1325794371.git.jani@nikula.org>\r
39 X-Mailer: git-send-email 1.7.5.4\r
40 In-Reply-To: <cover.1325794371.git.jani@nikula.org>\r
41 References: <cover.1325794371.git.jani@nikula.org>\r
42 In-Reply-To: <cover.1325794371.git.jani@nikula.org>\r
43 References: <cover.1325794371.git.jani@nikula.org>\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Thu, 05 Jan 2012 20:25:29 -0000\r
57 \r
58 Use the new notmuch argument parser to handle arguments in "notmuch\r
59 reply". There should be no functional changes.\r
60 \r
61 Signed-off-by: Jani Nikula <jani@nikula.org>\r
62 ---\r
63  notmuch-reply.c |   75 +++++++++++++++++++++++++++----------------------------\r
64  1 files changed, 37 insertions(+), 38 deletions(-)\r
65 \r
66 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
67 index 1f33a86..000f6da 100644\r
68 --- a/notmuch-reply.c\r
69 +++ b/notmuch-reply.c\r
70 @@ -612,62 +612,61 @@ notmuch_reply_format_headers_only(void *ctx,\r
71      return 0;\r
72  }\r
73  \r
74 +enum {\r
75 +    FORMAT_DEFAULT,\r
76 +    FORMAT_HEADERS_ONLY,\r
77 +};\r
78 +\r
79  int\r
80  notmuch_reply_command (void *ctx, int argc, char *argv[])\r
81  {\r
82      notmuch_config_t *config;\r
83      notmuch_database_t *notmuch;\r
84      notmuch_query_t *query;\r
85 -    char *opt, *query_string;\r
86 -    int i, ret = 0;\r
87 +    char *query_string;\r
88 +    int opt_index, ret = 0;\r
89      int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);\r
90      notmuch_show_params_t params = { .part = -1 };\r
91 +    int format = FORMAT_DEFAULT;\r
92 +    notmuch_bool_t decrypt = FALSE;\r
93 +\r
94 +    notmuch_opt_desc_t options[] = {\r
95 +       { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',\r
96 +         (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },\r
97 +                                 { "headers-only", FORMAT_HEADERS_ONLY },\r
98 +                                 { 0, 0 } } },\r
99 +       { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },\r
100 +       { 0, 0, 0, 0, 0 }\r
101 +    };\r
102  \r
103 -    reply_format_func = notmuch_reply_format_default;\r
104 -\r
105 -    argc--; argv++; /* skip subcommand argument */\r
106 +    opt_index = parse_arguments (argc, argv, options, 1);\r
107 +    if (opt_index < 0) {\r
108 +       /* diagnostics already printed */\r
109 +       return 1;\r
110 +    }\r
111  \r
112 -    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
113 -       if (strcmp (argv[i], "--") == 0) {\r
114 -           i++;\r
115 -           break;\r
116 -       }\r
117 -        if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
118 -           opt = argv[i] + sizeof ("--format=") - 1;\r
119 -           if (strcmp (opt, "default") == 0) {\r
120 -               reply_format_func = notmuch_reply_format_default;\r
121 -           } else if (strcmp (opt, "headers-only") == 0) {\r
122 -               reply_format_func = notmuch_reply_format_headers_only;\r
123 -           } else {\r
124 -               fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
125 -               return 1;\r
126 -           }\r
127 -       } else if ((STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {\r
128 -           if (params.cryptoctx == NULL) {\r
129 -               GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);\r
130 -               if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg"))) {\r
131 -                   fprintf (stderr, "Failed to construct gpg context.\n");\r
132 -               } else {\r
133 -                   params.decrypt = TRUE;\r
134 -                   g_mime_gpg_context_set_always_trust((GMimeGpgContext*)params.cryptoctx, FALSE);\r
135 -               }\r
136 -               g_object_unref (session);\r
137 -               session = NULL;\r
138 -           }\r
139 +    if (format == FORMAT_HEADERS_ONLY)\r
140 +       reply_format_func = notmuch_reply_format_headers_only;\r
141 +    else\r
142 +       reply_format_func = notmuch_reply_format_default;\r
143 +\r
144 +    if (decrypt) {\r
145 +       GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
146 +       params.cryptoctx = g_mime_gpg_context_new (session, "gpg");\r
147 +       if (params.cryptoctx) {\r
148 +           g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);\r
149 +           params.decrypt = TRUE;\r
150         } else {\r
151 -           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
152 -           return 1;\r
153 +           fprintf (stderr, "Failed to construct gpg context.\n");\r
154         }\r
155 +       g_object_unref (session);\r
156      }\r
157  \r
158 -    argc -= i;\r
159 -    argv += i;\r
160 -\r
161      config = notmuch_config_open (ctx, NULL, NULL);\r
162      if (config == NULL)\r
163         return 1;\r
164  \r
165 -    query_string = query_string_from_args (ctx, argc, argv);\r
166 +    query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);\r
167      if (query_string == NULL) {\r
168         fprintf (stderr, "Out of memory\n");\r
169         return 1;\r
170 -- \r
171 1.7.5.4\r
172 \r