[PATCH v5 3/7] cli: search: Convert --output to keyword-flag argument
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 30 Oct 2014 23:59:29 +0000 (00:59 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:05:55 +0000 (10:05 -0800)
3b/a7b5c8e0114d7dca22a368233357ad60951d0f [new file with mode: 0644]

diff --git a/3b/a7b5c8e0114d7dca22a368233357ad60951d0f b/3b/a7b5c8e0114d7dca22a368233357ad60951d0f
new file mode 100644 (file)
index 0000000..b4ba15e
--- /dev/null
@@ -0,0 +1,143 @@
+Return-Path: <sojkam1@fel.cvut.cz>\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 0EE72429E30\r
+       for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 16:59:57 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[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 DVNCoY47OsYk for <notmuch@notmuchmail.org>;\r
+       Thu, 30 Oct 2014 16:59:52 -0700 (PDT)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+       by olra.theworths.org (Postfix) with ESMTP id D58EF431FDB\r
+       for <notmuch@notmuchmail.org>; Thu, 30 Oct 2014 16:59:45 -0700 (PDT)\r
+Received: from localhost (unknown [192.168.200.7])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id 44E725CCFF5\r
+       for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 00:59:45 +0100 (CET)\r
+X-Virus-Scanned: IMAP STYX AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+       by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
+       port 10044) with ESMTP id Z-M6ezEjNVDH for <notmuch@notmuchmail.org>;\r
+       Fri, 31 Oct 2014 00:59:40 +0100 (CET)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id 74A915CCFF6\r
+       for <notmuch@notmuchmail.org>; Fri, 31 Oct 2014 00:59:40 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
+       (envelope-from <sojkam1@fel.cvut.cz>)\r
+       id 1Xjzcs-0005bO-Qp; Fri, 31 Oct 2014 00:59:34 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v5 3/7] cli: search: Convert --output to keyword-flag argument\r
+Date: Fri, 31 Oct 2014 00:59:29 +0100\r
+Message-Id: <1414713573-21461-4-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <1414713573-21461-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1414713573-21461-1-git-send-email-sojkam1@fel.cvut.cz>\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: Thu, 30 Oct 2014 23:59:57 -0000\r
+\r
+This converts "notmuch search" to use the recently introduced\r
+keyword-flag argument parser. At this point, it only makes the code\r
+slightly less readable but following commits that add new --output\r
+keywords will profit from this.\r
+---\r
+ notmuch-search.c | 35 ++++++++++++++++++-----------------\r
+ 1 file changed, 18 insertions(+), 17 deletions(-)\r
+\r
+diff --git a/notmuch-search.c b/notmuch-search.c\r
+index 0c3e972..ce46877 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -23,11 +23,11 @@\r
+ #include "string-util.h"\r
\r
+ typedef enum {\r
+-    OUTPUT_SUMMARY,\r
+-    OUTPUT_THREADS,\r
+-    OUTPUT_MESSAGES,\r
+-    OUTPUT_FILES,\r
+-    OUTPUT_TAGS\r
++    OUTPUT_SUMMARY    = 1 << 0,\r
++    OUTPUT_THREADS    = 1 << 1,\r
++    OUTPUT_MESSAGES   = 1 << 2,\r
++    OUTPUT_FILES      = 1 << 3,\r
++    OUTPUT_TAGS               = 1 << 4,\r
+ } output_t;\r
\r
+ typedef struct {\r
+@@ -338,7 +338,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+     notmuch_database_t *notmuch;\r
+     search_options_t opt = {\r
+       .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
+-      .output = OUTPUT_SUMMARY,\r
++      .output = 0,\r
+       .offset = 0,\r
+       .limit = -1, /* unlimited */\r
+       .dupe = -1,\r
+@@ -367,7 +367,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+                                 { "text0", NOTMUCH_FORMAT_TEXT0 },\r
+                                 { 0, 0 } } },\r
+       { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },\r
+-      { NOTMUCH_OPT_KEYWORD, &opt.output, "output", 'o',\r
++      { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o',\r
+         (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY },\r
+                                 { "threads", OUTPUT_THREADS },\r
+                                 { "messages", OUTPUT_MESSAGES },\r
+@@ -390,6 +390,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+     if (opt_index < 0)\r
+       return EXIT_FAILURE;\r
\r
++    if (! opt.output)\r
++      opt.output = OUTPUT_SUMMARY;\r
++\r
+     switch (format_sel) {\r
+     case NOTMUCH_FORMAT_TEXT:\r
+       opt.format = sprinter_text_create (config, stdout);\r
+@@ -455,19 +458,17 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+       notmuch_query_set_omit_excluded (opt.query, exclude);\r
+     }\r
\r
+-    switch (opt.output) {\r
+-    default:\r
+-    case OUTPUT_SUMMARY:\r
+-    case OUTPUT_THREADS:\r
++    if (opt.output == OUTPUT_SUMMARY ||\r
++      opt.output == OUTPUT_THREADS)\r
+       ret = do_search_threads (&opt);\r
+-      break;\r
+-    case OUTPUT_MESSAGES:\r
+-    case OUTPUT_FILES:\r
++    else if (opt.output == OUTPUT_MESSAGES ||\r
++           opt.output == OUTPUT_FILES)\r
+       ret = do_search_messages (&opt);\r
+-      break;\r
+-    case OUTPUT_TAGS:\r
++    else if (opt.output == OUTPUT_TAGS)\r
+       ret = do_search_tags (notmuch, &opt);\r
+-      break;\r
++    else {\r
++      fprintf (stderr, "Error: the combination of outputs is not supported.\n");\r
++      ret = 1;\r
+     }\r
\r
+     notmuch_query_destroy (opt.query);\r
+-- \r
+2.1.1\r
+\r