unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/2] cli: make --entire-thread=false work for format=json.
Date: Sat, 10 Mar 2012 11:05:33 +0000	[thread overview]
Message-ID: <1331377533-30262-3-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1331377533-30262-1-git-send-email-markwalters1009@gmail.com>

The --entire-thread option in notmuch-show.c defaults to true when
format=json. Previously there was no way to turn this off. This patch
makes it respect --entire-thread=false.

The one subtlety is that we initialise a notmuch_bool_t to -1 to
indicate that the option parsing has not set it. This allows the code
to distinguish between the option being omitted from the command line,
and the option being set to false on the command line.
---
 notmuch-show.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/notmuch-show.c b/notmuch-show.c
index 05d51b2..8da1845 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -983,7 +983,12 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
     char *query_string;
     int opt_index, ret;
     const notmuch_show_format_t *format = &format_text;
-    notmuch_show_params_t params = { .part = -1 };
+
+    /* We abuse the notmuch_bool_t variable params.entire-thread by
+     * setting it to -1 to denote that the command line parsing has
+     * not set it. We ensure it is set to TRUE or FALSE before passing
+     * it to any other function.*/
+    notmuch_show_params_t params = { .part = -1, .entire_thread = -1 };
     int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
     notmuch_bool_t verify = FALSE;
     notmuch_bool_t no_exclude = FALSE;
@@ -1020,7 +1025,9 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
     switch (format_sel) {
     case NOTMUCH_FORMAT_JSON:
 	format = &format_json;
-	params.entire_thread = TRUE;
+	/* JSON defaults to entire-thread TRUE */
+	if (params.entire_thread == -1)
+	    params.entire_thread = TRUE;
 	break;
     case NOTMUCH_FORMAT_TEXT:
 	format = &format_text;
@@ -1042,6 +1049,10 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
 	params.raw = TRUE;
 	break;
     }
+    /* Default is entire-thread = FALSE except for format=json which
+     * is dealt with above. */
+    if (params.entire_thread == -1)
+	params.entire_thread = FALSE;
 
     if (params.decrypt || verify) {
 #ifdef GMIME_ATLEAST_26
-- 
1.7.9.1

  parent reply	other threads:[~2012-03-10 11:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-10 11:05 [PATCH v2 0/2] cli: Allow true/false parameter for boolean Mark Walters
2012-03-10 11:05 ` [PATCH 1/2] cli: Parsing. Allow true/false parameter for boolean options Mark Walters
2012-03-18 12:49   ` David Bremner
2012-03-10 11:05 ` Mark Walters [this message]
2012-03-14  2:47 ` [PATCH v2 0/2] cli: Allow true/false parameter for boolean Austin Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1331377533-30262-3-git-send-email-markwalters1009@gmail.com \
    --to=markwalters1009@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).