From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 289966DE278B for ; Sat, 1 Jul 2017 08:19:04 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.001 X-Spam-Level: X-Spam-Status: No, score=-0.001 tagged_above=-999 required=5 tests=[AWL=0.010, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id maITqc6_iB89 for ; Sat, 1 Jul 2017 08:19:03 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 68B2A6DE2788 for ; Sat, 1 Jul 2017 08:19:03 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1dRK7h-0002Iw-27; Sat, 01 Jul 2017 11:15:49 -0400 Received: (nullmailer pid 11074 invoked by uid 1000); Sat, 01 Jul 2017 15:18:59 -0000 From: David Bremner To: notmuch@freelists.org, notmuch@notmuchmail.org Subject: [PATCH 1/3] cli/show: convert keyword options to booleans Date: Sat, 1 Jul 2017 12:18:43 -0300 Message-Id: <20170701151845.10942-2-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170701151845.10942-1-david@tethera.net> References: <20170701151845.10942-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 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: Sat, 01 Jul 2017 15:19:04 -0000 There are two keyword options here that impliment boolean options. It is simpler to use the built-in boolean argument handling, and also more robust against divergence in parsing boolean and keyword arguments. --- notmuch-show.c | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/notmuch-show.c b/notmuch-show.c index 3ce4b63c..7104db1f 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -1009,18 +1009,6 @@ static const notmuch_show_format_t *formatters[] = { [NOTMUCH_FORMAT_RAW] = &format_raw, }; -enum { - ENTIRE_THREAD_DEFAULT = -1, - ENTIRE_THREAD_FALSE = FALSE, - ENTIRE_THREAD_TRUE = TRUE, -}; - -/* The following is to allow future options to be added more easily */ -enum { - EXCLUDE_TRUE, - EXCLUDE_FALSE, -}; - int notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) { @@ -1036,8 +1024,11 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) .output_body = TRUE, }; int format = NOTMUCH_FORMAT_NOT_SPECIFIED; - int exclude = EXCLUDE_TRUE; - int entire_thread = ENTIRE_THREAD_DEFAULT; + int exclude = TRUE; + + /* This value corresponds to neither true nor false being passed + * on the command line */ + int entire_thread = -1; notmuch_bool_t single_message; notmuch_opt_desc_t options[] = { @@ -1049,15 +1040,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) { "raw", NOTMUCH_FORMAT_RAW }, { 0, 0 } } }, { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 }, - { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x', - (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, - { "false", EXCLUDE_FALSE }, - { 0, 0 } } }, - { NOTMUCH_OPT_KEYWORD, &entire_thread, "entire-thread", 't', - (notmuch_keyword_t []){ { "true", ENTIRE_THREAD_TRUE }, - { "false", ENTIRE_THREAD_FALSE }, - { "", ENTIRE_THREAD_TRUE }, - { 0, 0 } } }, + { NOTMUCH_OPT_BOOLEAN, &exclude, "exclude", 'x', 0 }, + { NOTMUCH_OPT_BOOLEAN, &entire_thread, "entire-thread", 't', 0 }, { NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 }, { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 }, { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.verify, "verify", 'v', 0 }, @@ -1102,7 +1086,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) /* Default is entire-thread = FALSE except for format=json and * format=sexp. */ - if (entire_thread == ENTIRE_THREAD_DEFAULT) { + if (entire_thread != FALSE && entire_thread != TRUE) { if (format == NOTMUCH_FORMAT_JSON || format == NOTMUCH_FORMAT_SEXP) params.entire_thread = TRUE; else @@ -1182,7 +1166,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) } } - if (exclude == EXCLUDE_FALSE) { + if (exclude == FALSE) { notmuch_query_set_omit_excluded (query, FALSE); params.omit_excluded = FALSE; } -- 2.11.0