Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id BD22B429E26 for ; Tue, 15 Nov 2011 12:09:18 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jEDSprlgH1Mn for ; Tue, 15 Nov 2011 12:09:14 -0800 (PST) Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8E5A6431FB6 for ; Tue, 15 Nov 2011 12:09:14 -0800 (PST) Received: by mail-bw0-f53.google.com with SMTP id q10so8918567bka.26 for ; Tue, 15 Nov 2011 12:09:14 -0800 (PST) Received: by 10.204.157.135 with SMTP id b7mr11084345bkx.122.1321387754118; Tue, 15 Nov 2011 12:09:14 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id a21sm18244988fao.18.2011.11.15.12.09.11 (version=SSLv3 cipher=OTHER); Tue, 15 Nov 2011 12:09:13 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v7 4/6] cli: add support for --output parameter in notmuch count Date: Tue, 15 Nov 2011 22:08:51 +0200 Message-Id: <6efffc4f5a87a2adb0d9762a138e07d5e595e3d0.1321386762.git.jani@nikula.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: In-Reply-To: References: X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Nov 2011 20:09:18 -0000 Add support for --output=messages (which remains the default) and --output=threads to notmuch count. Signed-off-by: Jani Nikula --- NEWS | 5 +++++ notmuch-count.c | 18 ++++++++++++++++-- notmuch.1 | 29 +++++++++++++++++++++++++---- notmuch.c | 20 ++++++++++++++++---- 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index f224d02..7bd9987 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,11 @@ Add "notmuch search" --offset and --limit options The search command now takes options --offset=[-]N and --limit=N to limit the number of results shown. +Add "notmuch count --output" option + + The count command is now capable of counting threads in addition to + messages. This is selected using the new --output=(threads|messages) option. + Optimizations ------------- diff --git a/notmuch-count.c b/notmuch-count.c index a35be40..20ce334 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -29,6 +29,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) notmuch_query_t *query; char *query_str; int i; + notmuch_bool_t output_messages = TRUE; argc--; argv++; /* skip subcommand argument */ @@ -37,7 +38,17 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) i++; break; } - { + if (STRNCMP_LITERAL (argv[i], "--output=") == 0) { + const char *opt = argv[i] + sizeof ("--output=") - 1; + if (strcmp (opt, "threads") == 0) { + output_messages = FALSE; + } else if (strcmp (opt, "messages") == 0) { + output_messages = TRUE; + } else { + fprintf (stderr, "Invalid value for --output: %s\n", opt); + return 1; + } + } else { fprintf (stderr, "Unrecognized option: %s\n", argv[i]); return 1; } @@ -71,7 +82,10 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) return 1; } - printf ("%u\n", notmuch_query_count_messages(query)); + if (output_messages) + printf ("%u\n", notmuch_query_count_messages (query)); + else + printf ("%u\n", notmuch_query_count_threads (query)); notmuch_query_destroy (query); notmuch_database_close (notmuch); diff --git a/notmuch.1 b/notmuch.1 index cda777b..bc2f965 100644 --- a/notmuch.1 +++ b/notmuch.1 @@ -372,14 +372,35 @@ section below for details of the supported syntax for . .RE .RS 4 .TP 4 -.BR count " ..." +.BR count " [options...] ..." Count messages matching the search terms. -The number of matching messages is output to stdout. +The number of matching messages (or threads) is output to stdout. -With no search terms, a count of all messages in the database will be -displayed. +With no search terms, a count of all messages (or threads) in the database will +be displayed. + +Supported options for +.B count +include +.RS 4 +.TP 4 +.B \-\-output=(messages|threads) + +.RS 4 +.TP 4 +.B messages + +Output the number of matching messages. This is the default. +.RE +.RS 4 +.TP 4 +.B threads + +Output the number of matching threads. +.RE +.RE .RE .RE diff --git a/notmuch.c b/notmuch.c index 394371d..77973f8 100644 --- a/notmuch.c +++ b/notmuch.c @@ -328,12 +328,24 @@ static command_t commands[] = { "\tSee \"notmuch help search-terms\" for details of the search\n" "\tterms syntax." }, { "count", notmuch_count_command, - " [...]", + "[options...] [...]", "Count messages matching the search terms.", - "\tThe number of matching messages is output to stdout.\n" + "\tThe number of matching messages (or threads) is output to stdout.\n" + "\n" + "\tWith no search terms, a count of all messages (or threads) in\n" + "\tthe database will be displayed.\n" + "\n" + "\tSupported options for count include:\n" + "\n" + "\t--output=(messages|threads)\n" + "\n" + "\t\tmessages (default)\n" + "\n" + "\t\tOutput the number of matching messages.\n" + "\n" + "\t\tthreads\n" "\n" - "\tWith no search terms, a count of all messages in the database\n" - "\twill be displayed.\n" + "\t\tOutput the number of matching threads.\n" "\n" "\tSee \"notmuch help search-terms\" for details of the search\n" "\tterms syntax." }, -- 1.7.5.4