]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.c
cli: ignore config argument of notmuch_help_command
[notmuch] / notmuch.c
index 0fac0997865e6acd8622707c49d2d29999d488e3..f81922ed090dcb12d27d3cda434e2493f60393c7 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -47,7 +47,7 @@ static command_t commands[] = {
     { NULL, notmuch_command, TRUE,
       "Notmuch main command." },
     { "setup", notmuch_setup_command, TRUE,
-      "Interactively setup notmuch for first use." },
+      "Interactively set up notmuch for first use." },
     { "new", notmuch_new_command, FALSE,
       "Find and import new messages to the notmuch database." },
     { "insert", notmuch_insert_command, FALSE,
@@ -177,7 +177,7 @@ exec_man (const char *page)
 }
 
 static int
-notmuch_help_command (notmuch_config_t *config, int argc, char *argv[])
+notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[])
 {
     command_t *command;
     help_topic_t *topic;
@@ -202,14 +202,14 @@ notmuch_help_command (notmuch_config_t *config, int argc, char *argv[])
 
     command = find_command (argv[0]);
     if (command) {
-       char *page = talloc_asprintf (config, "notmuch-%s", command->name);
+       char *page = talloc_asprintf (NULL, "notmuch-%s", command->name);
        exec_man (page);
     }
 
     for (i = 0; i < ARRAY_SIZE (help_topics); i++) {
        topic = &help_topics[i];
        if (strcmp (argv[0], topic->name) == 0) {
-           char *page = talloc_asprintf (config, "notmuch-%s", topic->name);
+           char *page = talloc_asprintf (NULL, "notmuch-%s", topic->name);
            exec_man (page);
        }
     }
@@ -314,8 +314,16 @@ main (int argc, char *argv[])
        goto DONE;
     }
 
-    if (print_help) {
-       ret = notmuch_help_command (NULL, argc - 1, &argv[1]);
+    /* Handle notmuch --help [command] and notmuch command --help. */
+    if (print_help ||
+       (opt_index + 1 < argc && strcmp (argv[opt_index + 1], "--help") == 0)) {
+       /*
+        * Pass the first positional argument as argv[1] so the help
+        * command can give help for it. The help command ignores the
+        * argv[0] passed to it.
+        */
+       ret = notmuch_help_command (NULL, argc - opt_index + 1,
+                                   argv + opt_index - 1);
        goto DONE;
     }