From c90554b52a9744150e45e215d6826f69dc8d087f Mon Sep 17 00:00:00 2001 From: David Bremner Date: Mon, 6 Apr 2015 21:22:38 +0900 Subject: [PATCH] [Patch v2 4/4] cli: add standard option processing to config and setup --- 7e/f3373b7c48b7bf94527a01cb5657990536cae0 | 139 ++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 7e/f3373b7c48b7bf94527a01cb5657990536cae0 diff --git a/7e/f3373b7c48b7bf94527a01cb5657990536cae0 b/7e/f3373b7c48b7bf94527a01cb5657990536cae0 new file mode 100644 index 000000000..a44cc4195 --- /dev/null +++ b/7e/f3373b7c48b7bf94527a01cb5657990536cae0 @@ -0,0 +1,139 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 7F6F76DE1AFA + for ; Mon, 6 Apr 2015 05:24:11 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.474 +X-Spam-Level: +X-Spam-Status: No, score=0.474 tagged_above=-999 required=5 tests=[AWL=0.464, + T_HEADER_FROM_DIFFERENT_DOMAINS=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 jL268kYEiiJn for ; + Mon, 6 Apr 2015 05:24:09 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id B10F56DE1AEA + for ; Mon, 6 Apr 2015 05:24:09 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1Yf63r-00058v-SP; Mon, 06 Apr 2015 12:23:27 +0000 +Received: (nullmailer pid 3286 invoked by uid 1000); Mon, 06 Apr 2015 + 12:22:58 -0000 +From: David Bremner +To: David Bremner , notmuch@notmuchmail.org +Subject: [Patch v2 4/4] cli: add standard option processing to config and + setup +Date: Mon, 6 Apr 2015 21:22:38 +0900 +Message-Id: <1428322958-2887-5-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1428322958-2887-1-git-send-email-david@tethera.net> +References: <87d23ixnr7.fsf@maritornes.cs.unb.ca> + <1428322958-2887-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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, 06 Apr 2015 12:24:11 -0000 + +In particular this fixes a recently encountered bug where the +"--config" argument to "notmuch setup" is silently ignored, which the +unpleasant consequence of overwriting the users config file. +--- + notmuch-config.c | 16 +++++++++++++++- + notmuch-setup.c | 12 ++++++++++++ + test/random-corpus.c | 9 +++++++++ + 3 files changed, 36 insertions(+), 1 deletion(-) + +diff --git a/notmuch-config.c b/notmuch-config.c +index 2d5c297..f2cd6a8 100644 +--- a/notmuch-config.c ++++ b/notmuch-config.c +@@ -872,8 +872,22 @@ int + notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]) + { + int ret; ++ int opt_index; + +- argc--; argv++; /* skip subcommand argument */ ++ notmuch_opt_desc_t options[] = { ++ { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, ++ { 0, 0, 0, 0, 0 } ++ }; ++ ++ opt_index = parse_arguments (argc, argv, options, 1); ++ if (opt_index < 0) ++ return EXIT_FAILURE; ++ ++ notmuch_process_shared_options (argv[0]); ++ ++ /* skip at least subcommand argument */ ++ argc-= opt_index; ++ argv+= opt_index; + + if (argc < 1) { + fprintf (stderr, "Error: notmuch config requires at least one argument.\n"); +diff --git a/notmuch-setup.c b/notmuch-setup.c +index 36a6171..6a020dc 100644 +--- a/notmuch-setup.c ++++ b/notmuch-setup.c +@@ -133,6 +133,7 @@ notmuch_setup_command (notmuch_config_t *config, + size_t new_tags_len; + const char **search_exclude_tags; + size_t search_exclude_tags_len; ++ int opt_index; + + #define prompt(format, ...) \ + do { \ +@@ -145,6 +146,17 @@ notmuch_setup_command (notmuch_config_t *config, + chomp_newline (response); \ + } while (0) + ++ notmuch_opt_desc_t options[] = { ++ { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, ++ { 0, 0, 0, 0, 0 } ++ }; ++ ++ opt_index = parse_arguments (argc, argv, options, 1); ++ if (opt_index < 0) ++ return EXIT_FAILURE; ++ ++ notmuch_process_shared_options ("setup"); ++ + if (notmuch_config_is_new (config)) + welcome_message_pre_setup (); + +diff --git a/test/random-corpus.c b/test/random-corpus.c +index 790193d..6c467bb 100644 +--- a/test/random-corpus.c ++++ b/test/random-corpus.c +@@ -114,6 +114,15 @@ random_utf8_string (void *ctx, size_t char_count) + return buf; + } + ++/* stubs since we cannot link with notmuch.o */ ++const notmuch_opt_desc_t notmuch_shared_options[] = { ++ { 0, 0, 0, 0, 0 } ++}; ++ ++void ++notmuch_process_shared_options (unused (const char *dummy)) ++{ ++} + + int + main (int argc, char **argv) +-- +2.1.4 + -- 2.26.2