X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.c;h=9580c3fe1e062b4821b8bd10677aafbd8f5ddc5c;hp=3ce30b456a369266d9831ccf089deeb66763f7ad;hb=d0553ad524f241ba42f685cba6745c8a3a9ba20a;hpb=0018a8d787a98f80c665061daa9b0c73839d3666 diff --git a/notmuch.c b/notmuch.c index 3ce30b45..9580c3fe 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 *) ¬much_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); @@ -351,11 +381,11 @@ main (int argc, char *argv[]) goto DONE; } - notmuch_process_shared_options (NULL); - if (opt_index < argc) command_name = argv[opt_index]; + notmuch_process_shared_options (command_name); + command = find_command (command_name); if (!command) { fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",