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 065AA429E31 for ; Fri, 4 Nov 2011 13:25:30 -0700 (PDT) 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 Z2bOdaxCu83s for ; Fri, 4 Nov 2011 13:25:28 -0700 (PDT) Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 959C2429E2F for ; Fri, 4 Nov 2011 13:25:27 -0700 (PDT) Received: by mail-fx0-f53.google.com with SMTP id n15so52582faa.26 for ; Fri, 04 Nov 2011 13:25:27 -0700 (PDT) Received: by 10.223.76.66 with SMTP id b2mr27329292fak.15.1320438327178; Fri, 04 Nov 2011 13:25:27 -0700 (PDT) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id l26sm18277004fad.17.2011.11.04.13.25.25 (version=SSLv3 cipher=OTHER); Fri, 04 Nov 2011 13:25:26 -0700 (PDT) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v3 4/7] cli: add support for --output parameter in notmuch count Date: Fri, 4 Nov 2011 22:25:12 +0200 Message-Id: <9bb08f8ab40e14b28137ea7a4d592d587efce0bc.1320349030.git.jani@nikula.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: In-Reply-To: References: Cc: amdragon@mit.edu 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: Fri, 04 Nov 2011 20:25:30 -0000 Add support for --output=messages (which remains the default) and --output=threads to notmuch count. Signed-off-by: Jani Nikula --- notmuch-count.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-) diff --git a/notmuch-count.c b/notmuch-count.c index a35be40..09b413e 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); -- 1.7.5.4