--- /dev/null
+Return-Path: <m.walters@qmul.ac.uk>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 7614C431FBC\r
+ for <notmuch@notmuchmail.org>; Sat, 26 May 2012 02:25:52 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+ NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 9Zq92mnC86tJ for <notmuch@notmuchmail.org>;\r
+ Sat, 26 May 2012 02:25:50 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 37828431FB6\r
+ for <notmuch@notmuchmail.org>; Sat, 26 May 2012 02:25:50 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+ by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SYDFo-0005Bz-PL; Sat, 26 May 2012 10:25:45 +0100\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+ helo=localhost)\r
+ by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+ (envelope-from <m.walters@qmul.ac.uk>)\r
+ id 1SYDFo-00036t-Dp; Sat, 26 May 2012 10:25:44 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Peter Wang <novalazy@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v4 2/4] cli: make --entire-thread=false work for\r
+ format=json.\r
+In-Reply-To: <20120526121556.GA2328@hili.localdomain>\r
+References: <1335258675-29439-1-git-send-email-markwalters1009@gmail.com>\r
+ <1335258675-29439-3-git-send-email-markwalters1009@gmail.com>\r
+ <20120526121556.GA2328@hili.localdomain>\r
+User-Agent: Notmuch/0.13+38~g35cb1c9 (http://notmuchmail.org) Emacs/23.3.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sat, 26 May 2012 09:28:20 +0100\r
+Message-ID: <87txz3cpnf.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 8e0b804157069eb4539fffdf6b43ef77 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+ determine if it is\r
+ spam. We require at least 5.0 points to mark a message as spam.\r
+ This message scored -1.8 points.\r
+ Summary of the scoring: \r
+ * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+ * medium trust\r
+ * [138.37.6.40 listed in list.dnswl.org]\r
+ * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+ provider * (markwalters1009[at]gmail.com)\r
+ * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+ * domain\r
+ * 0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 26 May 2012 09:25:52 -0000\r
+\r
+\r
+On Sat, 26 May 2012, Peter Wang <novalazy@gmail.com> wrote:\r
+> On Tue, 24 Apr 2012 10:11:13 +0100, Mark Walters <markwalters1009@gmail.com> wrote:\r
+>> The --entire-thread option in notmuch-show.c defaults to true when\r
+>> format=json. Previously there was no way to turn this off. This patch\r
+>> makes it respect --entire-thread=false.\r
+>> \r
+>> The one subtlety is that we initialise a notmuch_bool_t to -1 to\r
+>> indicate that the option parsing has not set it. This allows the code\r
+>> to distinguish between the option being omitted from the command line,\r
+>> and the option being set to false on the command line.\r
+>> ---\r
+>> notmuch-show.c | 16 ++++++++++++++--\r
+>> 1 files changed, 14 insertions(+), 2 deletions(-)\r
+>> \r
+>> diff --git a/notmuch-show.c b/notmuch-show.c\r
+>> index 0d21f1a..48551bb 100644\r
+>> --- a/notmuch-show.c\r
+>> +++ b/notmuch-show.c\r
+>> @@ -996,7 +996,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
+>> char *query_string;\r
+>> int opt_index, ret;\r
+>> const notmuch_show_format_t *format = &format_text;\r
+>> - notmuch_show_params_t params = { .part = -1, .omit_excluded = TRUE };\r
+>> +\r
+>> + /* We abuse the notmuch_bool_t variable params.entire-thread by\r
+>> + * setting it to -1 to denote that the command line parsing has\r
+>> + * not set it. We ensure it is set to TRUE or FALSE before passing\r
+>> + * it to any other function.*/\r
+>> + notmuch_show_params_t params = { .part = -1, .entire_thread = -1 };\r
+>> +\r
+>> int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;\r
+>> notmuch_bool_t verify = FALSE;\r
+>> int exclude = EXCLUDE_TRUE;\r
+>\r
+> Hi Mark,\r
+>\r
+> As an alternative to the abuse, could you just treat it as with exclude,\r
+> using an enum with three values (TRUE|FALSE|DEFAULT)?\r
+> Then set params.entire_thread afterwards.\r
+\r
+The reason I haven't done this is that the current command line parser\r
+does not allow keyword options to take default values: in other words\r
+--entire-thread without an "=<something>" would not be allowed.\r
+\r
+It is easy to change the keyword parsing code to allow this: I include a\r
+first draft of such a patch below. This would allow the solution you\r
+suggest and thus avoid the hack/abuse. What do people think?\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+---\r
+ command-line-arguments.c | 13 ++++++++++---\r
+ 1 files changed, 10 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/command-line-arguments.c b/command-line-arguments.c\r
+index 76b185f..d40c7e6 100644\r
+--- a/command-line-arguments.c\r
++++ b/command-line-arguments.c\r
+@@ -11,10 +11,16 @@\r
+ */\r
+ \r
+ static notmuch_bool_t\r
+-_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {\r
++_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {\r
+ \r
+ const notmuch_keyword_t *keywords = arg_desc->keywords;\r
+ \r
++ if (next == 0) {\r
++/* No keyword given so return first option as default */\r
++ *((int *)arg_desc->output_var) = keywords->value;\r
++ return TRUE;\r
++ }\r
++\r
+ while (keywords->name) {\r
+ if (strcmp (arg_str, keywords->name) == 0) {\r
+ if (arg_desc->output_var) {\r
+@@ -99,7 +105,8 @@ parse_option (const char *arg,\r
+ */\r
+ if (next != '=' && next != ':' && next != 0) return FALSE;\r
+ if (next == 0) {\r
+- if (try->opt_type != NOTMUCH_OPT_BOOLEAN)\r
++ if (try->opt_type != NOTMUCH_OPT_BOOLEAN &&\r
++ try->opt_type != NOTMUCH_OPT_KEYWORD)\r
+ return FALSE;\r
+ } else {\r
+ if (value[0] == 0) return FALSE;\r
+@@ -110,7 +117,7 @@ parse_option (const char *arg,\r
+ \r
+ switch (try->opt_type) {\r
+ case NOTMUCH_OPT_KEYWORD:\r
+- return _process_keyword_arg (try, value);\r
++ return _process_keyword_arg (try, next, value);\r
+ break;\r
+ case NOTMUCH_OPT_BOOLEAN:\r
+ return _process_boolean_arg (try, next, value);\r
+-- \r
+1.7.9.1\r
+\r