[PATCH 4/4] cli: add standard option processing to config and setup

David Bremner david at tethera.net
Sun Apr 5 13:59:34 PDT 2015


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 | 12 ++++++++++++
 notmuch-setup.c  | 12 ++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/notmuch-config.c b/notmuch-config.c
index 2d5c297..054dd3b 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -872,6 +872,18 @@ int
 notmuch_config_command (notmuch_config_t *config, int argc, char *argv[])
 {
     int ret;
+    int opt_index;
+
+    notmuch_opt_desc_t options[] = {
+	{ NOTMUCH_OPT_INHERIT, (void *) &notmuch_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]);
 
     argc--; argv++; /* skip subcommand argument */
 
diff --git a/notmuch-setup.c b/notmuch-setup.c
index 36a6171..5fc6e25 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 *) &notmuch_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]);
+
     if (notmuch_config_is_new (config))
 	welcome_message_pre_setup ();
 
-- 
2.1.4



More information about the notmuch mailing list