From: Michal Sojka Date: Fri, 31 Oct 2014 21:53:57 +0000 (+0100) Subject: [PATCH v6 3/7] cli: search: Convert --output to keyword-flag argument X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e3be3623fe3cd88104b66c434644582d326b9346;p=notmuch-archives.git [PATCH v6 3/7] cli: search: Convert --output to keyword-flag argument --- diff --git a/88/19077b46249ed3a0fa1b020ec1189bb1dbe32d b/88/19077b46249ed3a0fa1b020ec1189bb1dbe32d new file mode 100644 index 000000000..c9c7ff250 --- /dev/null +++ b/88/19077b46249ed3a0fa1b020ec1189bb1dbe32d @@ -0,0 +1,143 @@ +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 27422431FC2 + for ; Fri, 31 Oct 2014 14:54:33 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] 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 6hrkkyh9OczW for ; + Fri, 31 Oct 2014 14:54:29 -0700 (PDT) +Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) + by olra.theworths.org (Postfix) with ESMTP id 9344B431FC9 + for ; Fri, 31 Oct 2014 14:54:21 -0700 (PDT) +Received: from localhost (unknown [192.168.200.7]) + by max.feld.cvut.cz (Postfix) with ESMTP id 463943D3E94 + for ; Fri, 31 Oct 2014 22:54:19 +0100 (CET) +X-Virus-Scanned: IMAP STYX AMAVIS +Received: from max.feld.cvut.cz ([192.168.200.1]) + by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new, + port 10044) with ESMTP id bn1NSzYmuNxh for ; + Fri, 31 Oct 2014 22:54:14 +0100 (CET) +Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34]) + by max.feld.cvut.cz (Postfix) with ESMTP id 6A4105CCE59 + for ; Fri, 31 Oct 2014 22:54:14 +0100 (CET) +Received: from wsh by steelpick.2x.cz with local (Exim 4.84) + (envelope-from ) + id 1XkK92-0007hl-Ms; Fri, 31 Oct 2014 22:54:08 +0100 +From: Michal Sojka +To: notmuch@notmuchmail.org +Subject: [PATCH v6 3/7] cli: search: Convert --output to keyword-flag argument +Date: Fri, 31 Oct 2014 22:53:57 +0100 +Message-Id: <1414792441-29555-4-git-send-email-sojkam1@fel.cvut.cz> +X-Mailer: git-send-email 2.1.1 +In-Reply-To: <1414792441-29555-1-git-send-email-sojkam1@fel.cvut.cz> +References: <1414792441-29555-1-git-send-email-sojkam1@fel.cvut.cz> +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, 31 Oct 2014 21:54:33 -0000 + +This converts "notmuch search" to use the recently introduced +keyword-flag argument parser. At this point, it only makes the code +slightly less readable but following commits that add new --output +keywords will profit from this. +--- + notmuch-search.c | 35 ++++++++++++++++++----------------- + 1 file changed, 18 insertions(+), 17 deletions(-) + +diff --git a/notmuch-search.c b/notmuch-search.c +index 0c3e972..ce46877 100644 +--- a/notmuch-search.c ++++ b/notmuch-search.c +@@ -23,11 +23,11 @@ + #include "string-util.h" + + typedef enum { +- OUTPUT_SUMMARY, +- OUTPUT_THREADS, +- OUTPUT_MESSAGES, +- OUTPUT_FILES, +- OUTPUT_TAGS ++ OUTPUT_SUMMARY = 1 << 0, ++ OUTPUT_THREADS = 1 << 1, ++ OUTPUT_MESSAGES = 1 << 2, ++ OUTPUT_FILES = 1 << 3, ++ OUTPUT_TAGS = 1 << 4, + } output_t; + + typedef struct { +@@ -338,7 +338,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) + notmuch_database_t *notmuch; + search_options_t opt = { + .sort = NOTMUCH_SORT_NEWEST_FIRST, +- .output = OUTPUT_SUMMARY, ++ .output = 0, + .offset = 0, + .limit = -1, /* unlimited */ + .dupe = -1, +@@ -367,7 +367,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) + { "text0", NOTMUCH_FORMAT_TEXT0 }, + { 0, 0 } } }, + { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 }, +- { NOTMUCH_OPT_KEYWORD, &opt.output, "output", 'o', ++ { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o', + (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY }, + { "threads", OUTPUT_THREADS }, + { "messages", OUTPUT_MESSAGES }, +@@ -390,6 +390,9 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) + if (opt_index < 0) + return EXIT_FAILURE; + ++ if (! opt.output) ++ opt.output = OUTPUT_SUMMARY; ++ + switch (format_sel) { + case NOTMUCH_FORMAT_TEXT: + opt.format = sprinter_text_create (config, stdout); +@@ -455,19 +458,17 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) + notmuch_query_set_omit_excluded (opt.query, exclude); + } + +- switch (opt.output) { +- default: +- case OUTPUT_SUMMARY: +- case OUTPUT_THREADS: ++ if (opt.output == OUTPUT_SUMMARY || ++ opt.output == OUTPUT_THREADS) + ret = do_search_threads (&opt); +- break; +- case OUTPUT_MESSAGES: +- case OUTPUT_FILES: ++ else if (opt.output == OUTPUT_MESSAGES || ++ opt.output == OUTPUT_FILES) + ret = do_search_messages (&opt); +- break; +- case OUTPUT_TAGS: ++ else if (opt.output == OUTPUT_TAGS) + ret = do_search_tags (notmuch, &opt); +- break; ++ else { ++ fprintf (stderr, "Error: the combination of outputs is not supported.\n"); ++ ret = 1; + } + + notmuch_query_destroy (opt.query); +-- +2.1.1 +