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