Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / bb / 63a20561dd3616119ea2407a012e9364886507
1 Return-Path: <amdragon@mit.edu>\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 9929C431FBC\r
6         for <notmuch@notmuchmail.org>; Mon,  3 Dec 2012 14:28:48 -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: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id PJQSSqbkpTsd for <notmuch@notmuchmail.org>;\r
16         Mon,  3 Dec 2012 14:28:48 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
18         [18.7.68.37])\r
19         by olra.theworths.org (Postfix) with ESMTP id 048C7431FAE\r
20         for <notmuch@notmuchmail.org>; Mon,  3 Dec 2012 14:28:47 -0800 (PST)\r
21 X-AuditID: 12074425-b7f606d0000008ea-44-50bd279fa48e\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 1B.AA.02282.F972DB05; Mon,  3 Dec 2012 17:28:47 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id qB3MSkBO032372; \r
27         Mon, 3 Dec 2012 17:28:47 -0500\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qB3MSi65014301\r
32         (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);\r
33         Mon, 3 Dec 2012 17:28:46 -0500 (EST)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1TfeVI-00047r-GZ; Mon, 03 Dec 2012 17:28:44 -0500\r
37 Date: Mon, 3 Dec 2012 17:28:44 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Jani Nikula <jani@nikula.org>\r
40 Subject: Re: [PATCH 2/2] cli: convert "notmuch new" to the argument parser\r
41 Message-ID: <20121203222844.GH1020@mit.edu>\r
42 References:\r
43  <c4f2a1048763950dd14e13c99a4e7eb333be8c9d.1354568072.git.jani@nikula.org>\r
44         <e31ac6b2ceed533f8ac5386a010f4c052e09502e.1354568072.git.jani@nikula.org>\r
45 MIME-Version: 1.0\r
46 Content-Type: text/plain; charset=us-ascii\r
47 Content-Disposition: inline\r
48 In-Reply-To:\r
49  <e31ac6b2ceed533f8ac5386a010f4c052e09502e.1354568072.git.jani@nikula.org>\r
50 User-Agent: Mutt/1.5.21 (2010-09-15)\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IR4hTV1p2vvjfAYOIrboum6c4W12/OZHZg\r
53         8rh1/zW7x7NVt5gDmKK4bFJSczLLUov07RK4MubsDS14JllxoecMawPjKeEuRk4OCQETiRWP\r
54         XrFB2GISF+6tB7K5OIQE9jFKvNn9gwXCWc8osePJQkYI5wKTxN6V16DKljBKNH2ayQ7SzyKg\r
55         InH74UEmEJtNQENi2/7ljCC2iICixOaT+8FsZgFpiW+/m8FqhAW8JI68OwW2m1dAW+LKslZ2\r
56         iKELGSUONnUwQiQEJU7OfMIC0awlcePfS6BmDrBBy/9xgIQ5BcIkzrdOBJspCnTDlJPb2CYw\r
57         Cs1C0j0LSfcshO4FjMyrGGVTcqt0cxMzc4pTk3WLkxPz8lKLdC30cjNL9FJTSjcxgsKa3UV1\r
58         B+OEQ0qHGAU4GJV4eCfc2hMgxJpYVlyZe4hRkoNJSZRXSmJvgBBfUn5KZUZicUZ8UWlOavEh\r
59         RgkOZiUR3tfsQDnelMTKqtSifJiUNAeLkjjvjZSb/kIC6YklqdmpqQWpRTBZGQ4OJQneOjWg\r
60         RsGi1PTUirTMnBKENBMHJ8hwHqDhJSA1vMUFibnFmekQ+VOMilLivKwgCQGQREZpHlwvLO28\r
61         YhQHekWYVxSkigeYsuC6XwENZgIa/EJoN8jgkkSElFQDY7L3dZZm5v93b6hm3atRWjBj99dF\r
62         onL/rk8x7dxQGVV713a/Jv8Dkw0f2jVfLsmQff0+UfQZQ9YF39L9aQz6OTueHN+nsEZeT2j6\r
63         duNtBQrPzu3pnzqlZ2kZ46oWS3d1x8JXEb+uXN6wzPvYxP/zulTkqqeF/pDSOWwapPK11/3A\r
64         rtuG6mfnL1BiKc5INNRiLipOBABnzlOpFgMAAA==\r
65 Cc: notmuch@notmuchmail.org\r
66 X-BeenThere: notmuch@notmuchmail.org\r
67 X-Mailman-Version: 2.1.13\r
68 Precedence: list\r
69 List-Id: "Use and development of the notmuch mail system."\r
70         <notmuch.notmuchmail.org>\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
74 List-Post: <mailto:notmuch@notmuchmail.org>\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
77         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
78 X-List-Received-Date: Mon, 03 Dec 2012 22:28:48 -0000\r
79 \r
80 LGTM.  One minor nit below, but feel free to ignore it.\r
81 \r
82 Quoth Jani Nikula on Dec 03 at 10:56 pm:\r
83 > Use the notmuch argument parser to handle arguments in "notmuch\r
84 > new". As a side effect, this fixes broken STRNCMP_LITERAL usage that\r
85 > accepts, for example, --verbosefoo for --verbose.\r
86 > ---\r
87 >  notmuch-new.c |   38 +++++++++++++++++++-------------------\r
88 >  1 file changed, 19 insertions(+), 19 deletions(-)\r
89\r
90 > diff --git a/notmuch-new.c b/notmuch-new.c\r
91 > index 718a538..feb9c32 100644\r
92 > --- a/notmuch-new.c\r
93 > +++ b/notmuch-new.c\r
94 > @@ -36,8 +36,8 @@ typedef struct _filename_list {\r
95 >  \r
96 >  typedef struct {\r
97 >      int output_is_a_tty;\r
98 > -    int verbose;\r
99 > -    int debug;\r
100 > +    notmuch_bool_t verbose;\r
101 > +    notmuch_bool_t debug;\r
102 >      const char **new_tags;\r
103 >      size_t new_tags_length;\r
104 >      const char **new_ignore;\r
105 > @@ -853,28 +853,28 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
106 >      char *dot_notmuch_path;\r
107 >      struct sigaction action;\r
108 >      _filename_node_t *f;\r
109 > +    int opt_index;\r
110 >      int i;\r
111 >      notmuch_bool_t timer_is_active = FALSE;\r
112 > -    notmuch_bool_t run_hooks = TRUE;\r
113 > +    notmuch_bool_t no_hooks = FALSE;\r
114 >  \r
115 > -    add_files_state.verbose = 0;\r
116 > -    add_files_state.debug = 0;\r
117 > +    add_files_state.verbose = FALSE;\r
118 > +    add_files_state.debug = FALSE;\r
119 >      add_files_state.output_is_a_tty = isatty (fileno (stdout));\r
120 >  \r
121 > -    argc--; argv++; /* skip subcommand argument */\r
122 > +    notmuch_opt_desc_t options[] = {\r
123 > +     { NOTMUCH_OPT_BOOLEAN,  &add_files_state.verbose, "verbose", 'v', 0 },\r
124 > +     { NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },\r
125 > +     { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },\r
126 \r
127 Not that the single character arguments matter right now, but '-n' is\r
128 often used for "dry-run", which could actually apply to notmuch new.\r
129 \r
130 > +     { 0, 0, 0, 0, 0 }\r
131 > +    };\r
132 >  \r
133 > -    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
134 > -     if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
135 > -         add_files_state.verbose = 1;\r
136 > -     } else if (strcmp (argv[i], "--debug") == 0) {\r
137 > -         add_files_state.debug = 1;\r
138 > -     } else if (strcmp (argv[i], "--no-hooks") == 0) {\r
139 > -         run_hooks = FALSE;\r
140 > -     } else {\r
141 > -         fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
142 > -         return 1;\r
143 > -     }\r
144 > +    opt_index = parse_arguments (argc, argv, options, 1);\r
145 > +    if (opt_index < 0) {\r
146 > +     /* diagnostics already printed */\r
147 > +     return 1;\r
148 >      }\r
149 > +\r
150 >      config = notmuch_config_open (ctx, NULL, NULL);\r
151 >      if (config == NULL)\r
152 >       return 1;\r
153 > @@ -884,7 +884,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
154 >      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
155 >      db_path = notmuch_config_get_database_path (config);\r
156 >  \r
157 > -    if (run_hooks) {\r
158 > +    if (!no_hooks) {\r
159 >       ret = notmuch_run_hook (db_path, "pre-new");\r
160 >       if (ret)\r
161 >           return ret;\r
162 > @@ -1045,7 +1045,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
163 >  \r
164 >      notmuch_database_destroy (notmuch);\r
165 >  \r
166 > -    if (run_hooks && !ret && !interrupted)\r
167 > +    if (!no_hooks && !ret && !interrupted)\r
168 >       ret = notmuch_run_hook (db_path, "post-new");\r
169 >  \r
170 >      return ret || interrupted;\r