From b920f1b175742de7940c6af94a7af0339d60a2e2 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Tue, 4 Nov 2014 00:50:19 +0100 Subject: [PATCH] [PATCH v2 07/10] cli: search: Convert --output to keyword argument --- b3/59846101618ceb3d0de0aead4c85ebbb6b750c | 138 ++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 b3/59846101618ceb3d0de0aead4c85ebbb6b750c diff --git a/b3/59846101618ceb3d0de0aead4c85ebbb6b750c b/b3/59846101618ceb3d0de0aead4c85ebbb6b750c new file mode 100644 index 000000000..8bb6277c1 --- /dev/null +++ b/b3/59846101618ceb3d0de0aead4c85ebbb6b750c @@ -0,0 +1,138 @@ +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 13557431FAF + for ; Mon, 3 Nov 2014 15:51:19 -0800 (PST) +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 Ewmt8mnB6ANk for ; + Mon, 3 Nov 2014 15:51:13 -0800 (PST) +Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) + by olra.theworths.org (Postfix) with ESMTP id 93155429E34 + for ; Mon, 3 Nov 2014 15:50:52 -0800 (PST) +Received: from localhost (unknown [192.168.200.7]) + by max.feld.cvut.cz (Postfix) with ESMTP id 147A55CD008 + for ; Tue, 4 Nov 2014 00:50:52 +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 USTgdAnh_uU9 for ; + Tue, 4 Nov 2014 00:50:45 +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 E2D2A5CD00B + for ; Tue, 4 Nov 2014 00:50:40 +0100 (CET) +Received: from wsh by steelpick.2x.cz with local (Exim 4.84) + (envelope-from ) + id 1XlROM-0005Wn-6Y; Tue, 04 Nov 2014 00:50:34 +0100 +From: Michal Sojka +To: notmuch@notmuchmail.org +Subject: [PATCH v2 07/10] cli: search: Convert --output to keyword argument +Date: Tue, 4 Nov 2014 00:50:19 +0100 +Message-Id: <1415058622-21162-8-git-send-email-sojkam1@fel.cvut.cz> +X-Mailer: git-send-email 2.1.1 +In-Reply-To: <1415058622-21162-1-git-send-email-sojkam1@fel.cvut.cz> +References: <1415058622-21162-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: Mon, 03 Nov 2014 23:51:19 -0000 + +Now, when address related outputs are in a separate command, it makes +no sense to combine multiple --output options in search command line. +Using switch statement to handle different outputs is more readable +than a series of if statements. +--- + doc/man1/notmuch-search.rst | 3 --- + notmuch-search.c | 25 +++++++++++++------------ + 2 files changed, 13 insertions(+), 15 deletions(-) + +diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst +index 65df288..0cc2911 100644 +--- a/doc/man1/notmuch-search.rst ++++ b/doc/man1/notmuch-search.rst +@@ -78,9 +78,6 @@ Supported options for **search** include + by null characters (--format=text0), as a JSON array + (--format=json), or as an S-Expression list (--format=sexp). + +- This option can be given multiple times to combine different +- outputs. +- + ``--sort=``\ (**newest-first**\ \|\ **oldest-first**) + This option can be used to present results in either + chronological order (**oldest-first**) or reverse chronological +diff --git a/notmuch-search.c b/notmuch-search.c +index cbd84f5..402e860 100644 +--- a/notmuch-search.c ++++ b/notmuch-search.c +@@ -593,7 +593,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) + int opt_index, ret; + + notmuch_opt_desc_t options[] = { +- { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o', ++ { NOTMUCH_OPT_KEYWORD, &ctx->output, "output", 'o', + (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY }, + { "threads", OUTPUT_THREADS }, + { "messages", OUTPUT_MESSAGES }, +@@ -607,13 +607,11 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) + { 0, 0, 0, 0, 0 } + }; + ++ ctx->output = OUTPUT_SUMMARY; + opt_index = parse_arguments (argc, argv, options, 1); + if (opt_index < 0) + return EXIT_FAILURE; + +- if (! ctx->output) +- ctx->output = OUTPUT_SUMMARY; +- + if (ctx->output != OUTPUT_FILES && ctx->output != OUTPUT_MESSAGES && + ctx->dupe != -1) { + fprintf (stderr, "Error: --duplicate=N is only supported with --output=files and --output=messages.\n"); +@@ -624,17 +622,20 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) + argc - opt_index, argv + opt_index)) + return EXIT_FAILURE; + +- if (ctx->output == OUTPUT_SUMMARY || +- ctx->output == OUTPUT_THREADS) ++ switch (ctx->output) { ++ case OUTPUT_SUMMARY: ++ case OUTPUT_THREADS: + ret = do_search_threads (ctx); +- else if (ctx->output == OUTPUT_MESSAGES || +- ctx->output == OUTPUT_FILES) ++ break; ++ case OUTPUT_MESSAGES: ++ case OUTPUT_FILES: + ret = do_search_messages (ctx); +- else if (ctx->output == OUTPUT_TAGS) ++ break; ++ case OUTPUT_TAGS: + ret = do_search_tags (ctx); +- else { +- fprintf (stderr, "Error: the combination of outputs is not supported.\n"); +- ret = 1; ++ break; ++ default: ++ INTERNAL_ERROR ("Unexpected output"); + } + + _notmuch_search_cleanup (ctx); +-- +2.1.1 + -- 2.26.2