--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id CD430431FAE\r
+ for <notmuch@notmuchmail.org>; Tue, 29 Jan 2013 13:47:02 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id wt6ZMJb2I2ze for <notmuch@notmuchmail.org>;\r
+ Tue, 29 Jan 2013 13:47:01 -0800 (PST)\r
+Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com\r
+ [209.85.217.182]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 2417E431FDB\r
+ for <notmuch@notmuchmail.org>; Tue, 29 Jan 2013 13:46:55 -0800 (PST)\r
+Received: by mail-lb0-f182.google.com with SMTP id gg6so1345585lbb.13\r
+ for <notmuch@notmuchmail.org>; Tue, 29 Jan 2013 13:46:53 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=x-received:from:to:subject:date:message-id:x-mailer:in-reply-to\r
+ :references:in-reply-to:references:x-gm-message-state;\r
+ bh=uhL2LZNjBb0n5brjrnx0H08GMZdz6QacbnD+fdoOBbU=;\r
+ b=PSJpy3JNUhG0gHW8R1k17ZWT8bH57Bq5X/Jf1UrRr/bG2F+63cS56EDwydW6WhTJ1m\r
+ /9n9lucxEZkQuq5rkOvi8a9MM//nXelqtfDyHedwcGIrHSzv8U/9fVSa0UjF+kC/npLc\r
+ hFujV7nzJHNVuXLamws9PEX1MkK3JzR1OaAbUwCXQs8/CJm5FTmeh79/KhT56gRYRmlZ\r
+ h+DokuZ/euMBlykOQ6Q1oQ8p7Fq6vgL+o7NUcNCe0xMt2zmnhpAzld9fqSn6uofdF+Fo\r
+ //2QbppDfNHSGLLznKnTUr9xDl90jvtQn142dLgKJPahv5W19xt6Ojsjf7lNiSM4WPe3\r
+ RG+g==\r
+X-Received: by 10.112.48.130 with SMTP id l2mr1036206lbn.44.1359496013145;\r
+ Tue, 29 Jan 2013 13:46:53 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi.\r
+ [80.223.81.27])\r
+ by mx.google.com with ESMTPS id f8sm5597960lbg.2.2013.01.29.13.46.50\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Tue, 29 Jan 2013 13:46:52 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/6] cli: plug main notmuch command into subcommand machinery\r
+Date: Tue, 29 Jan 2013 23:46:22 +0200\r
+Message-Id:\r
+ <c1afb811a526ec08331af75d12d5edfd01bf9279.1359495450.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <cover.1359495450.git.jani@nikula.org>\r
+References: <cover.1359495450.git.jani@nikula.org>\r
+In-Reply-To: <cover.1359495450.git.jani@nikula.org>\r
+References: <cover.1359495450.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQmgBoKO3ZmBScS0a/lkLZAVeqS4wAASF/THun6FW89UYUqbwe/jp9XQV71Zu30zsCtkeG/O\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\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: Tue, 29 Jan 2013 21:47:03 -0000\r
+\r
+This also allows the main notmuch command to have arguments (though\r
+they are not used).\r
+---\r
+ notmuch.c | 26 +++++++++++++++++---------\r
+ 1 file changed, 17 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/notmuch.c b/notmuch.c\r
+index c47b998..67d5772 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -34,7 +34,13 @@ typedef struct command {\r
+ static int\r
+ notmuch_help_command (void *ctx, int argc, char *argv[]);\r
+ \r
++static int\r
++notmuch_command (void *ctx, int argc, char *argv[]);\r
++\r
+ static command_t commands[] = {\r
++ { NULL, notmuch_command,\r
++ NULL,\r
++ "Notmuch main command." },\r
+ { "setup", notmuch_setup_command,\r
+ NULL,\r
+ "Interactively setup notmuch for first use." },\r
+@@ -76,7 +82,8 @@ find_command (const char *name)\r
+ size_t i;\r
+ \r
+ for (i = 0; i < ARRAY_SIZE (commands); i++)\r
+- if (strcmp (name, commands[i].name) == 0)\r
++ if ((!name && !commands[i].name) ||\r
++ (name && commands[i].name && strcmp (name, commands[i].name) == 0))\r
+ return &commands[i];\r
+ \r
+ return NULL;\r
+@@ -101,8 +108,8 @@ usage (FILE *out)\r
+ for (i = 0; i < ARRAY_SIZE (commands); i++) {\r
+ command = &commands[i];\r
+ \r
+- fprintf (out, " %-11s %s\n",\r
+- command->name, command->summary);\r
++ if (command->name)\r
++ fprintf (out, " %-11s %s\n", command->name, command->summary);\r
+ }\r
+ \r
+ fprintf (out, "\n");\r
+@@ -192,7 +199,7 @@ notmuch_help_command (void *ctx, int argc, char *argv[])\r
+ * to be more clever about this in the future.\r
+ */\r
+ static int\r
+-notmuch (void *ctx)\r
++notmuch_command (void *ctx, unused(int argc), unused(char *argv[]))\r
+ {\r
+ notmuch_config_t *config;\r
+ char *db_path;\r
+@@ -255,6 +262,7 @@ main (int argc, char *argv[])\r
+ {\r
+ void *local;\r
+ char *talloc_report;\r
++ const char *command_name = NULL;\r
+ command_t *command;\r
+ notmuch_bool_t print_help=FALSE, print_version=FALSE;\r
+ int opt_index;\r
+@@ -276,9 +284,6 @@ main (int argc, char *argv[])\r
+ /* Globally default to the current output format version. */\r
+ notmuch_format_version = NOTMUCH_FORMAT_CUR;\r
+ \r
+- if (argc == 1)\r
+- return notmuch (local);\r
+-\r
+ opt_index = parse_arguments (argc, argv, options, 1);\r
+ if (opt_index < 0) {\r
+ /* diagnostics already printed */\r
+@@ -293,10 +298,13 @@ main (int argc, char *argv[])\r
+ return 0;\r
+ }\r
+ \r
+- command = find_command (argv[opt_index]);\r
++ if (opt_index < argc)\r
++ command_name = argv[opt_index];\r
++\r
++ command = find_command (command_name);\r
+ if (!command) {\r
+ fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n",\r
+- argv[opt_index]);\r
++ command_name);\r
+ return 1;\r
+ }\r
+ \r
+-- \r
+1.7.10.4\r
+\r