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 2EC18429E38 for ; Mon, 27 Oct 2014 07:51:35 -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 qD7vzyjmI2rt for ; Mon, 27 Oct 2014 07:51:31 -0700 (PDT) Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) by olra.theworths.org (Postfix) with ESMTP id 72682431E82 for ; Mon, 27 Oct 2014 07:51:17 -0700 (PDT) Received: from localhost (unknown [192.168.200.7]) by max.feld.cvut.cz (Postfix) with ESMTP id 6AAAE5CCF9E for ; Mon, 27 Oct 2014 15:51:13 +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 xwaXwEKFT3be for ; Mon, 27 Oct 2014 15:51:08 +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 9A58B5CCF97 for ; Mon, 27 Oct 2014 15:51:07 +0100 (CET) Received: from wsh by steelpick.2x.cz with local (Exim 4.84) (envelope-from ) id 1XildT-0000oe-HZ; Mon, 27 Oct 2014 15:51:07 +0100 From: Michal Sojka To: notmuch@notmuchmail.org Subject: [PATCH v4 3/6] cli: search: Convert --output to keyword-flag argument Date: Mon, 27 Oct 2014 15:50:52 +0100 Message-Id: <1414421455-3037-4-git-send-email-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1414421455-3037-1-git-send-email-sojkam1@fel.cvut.cz> References: <1414421455-3037-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, 27 Oct 2014 14:51:35 -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 patches 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