[PATCH v5 4/6] cli: add support for --output parameter in notmuch count
authorJani Nikula <jani@nikula.org>
Sun, 13 Nov 2011 19:48:38 +0000 (21:48 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:40:09 +0000 (09:40 -0800)
21/bb0928508a20e4fa3f097bb01213a67da439a7 [new file with mode: 0644]

diff --git a/21/bb0928508a20e4fa3f097bb01213a67da439a7 b/21/bb0928508a20e4fa3f097bb01213a67da439a7
new file mode 100644 (file)
index 0000000..70b7081
--- /dev/null
@@ -0,0 +1,172 @@
+Return-Path: <jani@nikula.org>\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 0B90F429E21\r
+       for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 11:49:07 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 YfGlU2mUuTvE for <notmuch@notmuchmail.org>;\r
+       Sun, 13 Nov 2011 11:49:05 -0800 (PST)\r
+Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 448A2429E38\r
+       for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 11:49:01 -0800 (PST)\r
+Received: by mail-bw0-f53.google.com with SMTP id q10so6225076bka.26\r
+       for <notmuch@notmuchmail.org>; Sun, 13 Nov 2011 11:49:00 -0800 (PST)\r
+Received: by 10.204.132.71 with SMTP id a7mr16316412bkt.93.1321213740775;\r
+       Sun, 13 Nov 2011 11:49:00 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id z15sm27183326bkv.4.2011.11.13.11.48.58\r
+       (version=SSLv3 cipher=OTHER); Sun, 13 Nov 2011 11:48:59 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 4/6] cli: add support for --output parameter in notmuch\r
+       count\r
+Date: Sun, 13 Nov 2011 21:48:38 +0200\r
+Message-Id:\r
+ <fe54c7f0c33d3d8694b57a05d4462229fe256605.1321212673.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1321212673.git.jani@nikula.org>\r
+References: <cover.1321212673.git.jani@nikula.org>\r
+In-Reply-To: <cover.1321212673.git.jani@nikula.org>\r
+References: <cover.1321212673.git.jani@nikula.org>\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: Sun, 13 Nov 2011 19:49:08 -0000\r
+\r
+Add support for --output=messages (which remains the default) and\r
+--output=threads to notmuch count.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ NEWS            |    5 +++++\r
+ notmuch-count.c |   18 ++++++++++++++++--\r
+ notmuch.1       |   29 +++++++++++++++++++++++++----\r
+ 3 files changed, 46 insertions(+), 6 deletions(-)\r
+\r
+diff --git a/NEWS b/NEWS\r
+index abc749a..78434d9 100644\r
+--- a/NEWS\r
++++ b/NEWS\r
+@@ -28,6 +28,11 @@ Add "notmuch search" --first and --maxitems options\r
+   The search command now takes options --first=[-]N and --maxitems=N to limit\r
+   the number of results shown.\r
\r
++Add "notmuch count --output" option\r
++\r
++  The count command is now capable of counting threads in addition to\r
++  messages. This is selected using the new --output=(threads|messages) option.\r
++\r
+ Notmuch 0.9 (2011-10-01)\r
+ ========================\r
\r
+diff --git a/notmuch-count.c b/notmuch-count.c\r
+index a35be40..20ce334 100644\r
+--- a/notmuch-count.c\r
++++ b/notmuch-count.c\r
+@@ -29,6 +29,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+     notmuch_query_t *query;\r
+     char *query_str;\r
+     int i;\r
++    notmuch_bool_t output_messages = TRUE;\r
\r
+     argc--; argv++; /* skip subcommand argument */\r
\r
+@@ -37,7 +38,17 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+           i++;\r
+           break;\r
+       }\r
+-      {\r
++      if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {\r
++          const char *opt = argv[i] + sizeof ("--output=") - 1;\r
++          if (strcmp (opt, "threads") == 0) {\r
++              output_messages = FALSE;\r
++          } else if (strcmp (opt, "messages") == 0) {\r
++              output_messages = TRUE;\r
++          } else {\r
++              fprintf (stderr, "Invalid value for --output: %s\n", opt);\r
++              return 1;\r
++          }\r
++      } else {\r
+           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
+           return 1;\r
+       }\r
+@@ -71,7 +82,10 @@ notmuch_count_command (void *ctx, int argc, char *argv[])\r
+       return 1;\r
+     }\r
\r
+-    printf ("%u\n", notmuch_query_count_messages(query));\r
++    if (output_messages)\r
++      printf ("%u\n", notmuch_query_count_messages (query));\r
++    else\r
++      printf ("%u\n", notmuch_query_count_threads (query));\r
\r
+     notmuch_query_destroy (query);\r
+     notmuch_database_close (notmuch);\r
+diff --git a/notmuch.1 b/notmuch.1\r
+index 15c3147..64114db 100644\r
+--- a/notmuch.1\r
++++ b/notmuch.1\r
+@@ -372,14 +372,35 @@ section below for details of the supported syntax for <search-terms>.\r
+ .RE\r
+ .RS 4\r
+ .TP 4\r
+-.BR count " <search-term>..."\r
++.BR count " [options...] <search-term>..."\r
\r
+ Count messages matching the search terms.\r
\r
+-The number of matching messages is output to stdout.\r
++The number of matching messages (or threads) is output to stdout.\r
\r
+-With no search terms, a count of all messages in the database will be\r
+-displayed.\r
++With no search terms, a count of all messages (or threads) in the database will\r
++be displayed.\r
++\r
++Supported options for\r
++.B count\r
++include\r
++.RS 4\r
++.TP 4\r
++.B \-\-output=(messages|threads)\r
++\r
++.RS 4\r
++.TP 4\r
++.B messages\r
++\r
++Output the number of matching messages. This is the default.\r
++.RE\r
++.RS 4\r
++.TP 4\r
++.B threads\r
++\r
++Output the number of matching threads.\r
++.RE\r
++.RE\r
+ .RE\r
+ .RE\r
\r
+-- \r
+1.7.5.4\r
+\r