From: Michal Sojka Date: Thu, 30 Oct 2014 23:59:29 +0000 (+0100) Subject: [PATCH v5 3/7] cli: search: Convert --output to keyword-flag argument X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0659e955d1c8c9829e0dadf5ee7837312a094969;p=notmuch-archives.git [PATCH v5 3/7] cli: search: Convert --output to keyword-flag argument --- diff --git a/3b/a7b5c8e0114d7dca22a368233357ad60951d0f b/3b/a7b5c8e0114d7dca22a368233357ad60951d0f new file mode 100644 index 000000000..b4ba15e96 --- /dev/null +++ b/3b/a7b5c8e0114d7dca22a368233357ad60951d0f @@ -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 0EE72429E30 + for ; Thu, 30 Oct 2014 16:59:57 -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 DVNCoY47OsYk for ; + Thu, 30 Oct 2014 16:59:52 -0700 (PDT) +Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) + by olra.theworths.org (Postfix) with ESMTP id D58EF431FDB + for ; Thu, 30 Oct 2014 16:59:45 -0700 (PDT) +Received: from localhost (unknown [192.168.200.7]) + by max.feld.cvut.cz (Postfix) with ESMTP id 44E725CCFF5 + for ; Fri, 31 Oct 2014 00:59:45 +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 Z-M6ezEjNVDH for ; + Fri, 31 Oct 2014 00:59:40 +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 74A915CCFF6 + for ; Fri, 31 Oct 2014 00:59:40 +0100 (CET) +Received: from wsh by steelpick.2x.cz with local (Exim 4.84) + (envelope-from ) + id 1Xjzcs-0005bO-Qp; Fri, 31 Oct 2014 00:59:34 +0100 +From: Michal Sojka +To: notmuch@notmuchmail.org +Subject: [PATCH v5 3/7] cli: search: Convert --output to keyword-flag argument +Date: Fri, 31 Oct 2014 00:59:29 +0100 +Message-Id: <1414713573-21461-4-git-send-email-sojkam1@fel.cvut.cz> +X-Mailer: git-send-email 2.1.1 +In-Reply-To: <1414713573-21461-1-git-send-email-sojkam1@fel.cvut.cz> +References: <1414713573-21461-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: Thu, 30 Oct 2014 23:59:57 -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 +