summaryrefslogtreecommitdiffstats
path: root/notmuch.c
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2015-04-06 05:34:55 +0900
committerDavid Bremner <david@tethera.net>2015-06-01 07:32:54 +0200
commit447ad6b4984c71881b7f97641c77f0a39b71a991 (patch)
treefec61c03ae38f2d57a1483fe6aaf9f9ff080ac7d /notmuch.c
parent0018a8d787a98f80c665061daa9b0c73839d3666 (diff)
cli: add standard option processing to config, help and setup
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.
Diffstat (limited to 'notmuch.c')
-rw-r--r--notmuch.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/notmuch.c b/notmuch.c
index 3ce30b45..c528dce2 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -71,6 +71,28 @@ notmuch_process_shared_options (const char *subcommand_name) {
}
}
+/* This is suitable for subcommands that do not actually open the
+ * database.
+ */
+int notmuch_minimal_options (const char *subcommand_name,
+ int argc, char **argv)
+{
+ 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 -1;
+
+ /* We can't use argv here as it is sometimes NULL */
+ notmuch_process_shared_options (subcommand_name);
+ return opt_index;
+}
static command_t commands[] = {
{ NULL, notmuch_command, TRUE,
@@ -250,7 +272,15 @@ _help_for (const char *topic_name)
static int
notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[])
{
- argc--; argv++; /* Ignore "help" */
+ int opt_index;
+
+ opt_index = notmuch_minimal_options ("help", argc, argv);
+ if (opt_index < 0)
+ return EXIT_FAILURE;
+
+ /* skip at least subcommand argument */
+ argc-= opt_index;
+ argv+= opt_index;
if (argc == 0) {
return _help_for (NULL);