--- /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 0A17B431FAE\r
+ for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 13:55:21 -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 nZT72VodYyjM for <notmuch@notmuchmail.org>;\r
+ Sun, 3 Mar 2013 13:55:20 -0800 (PST)\r
+Received: from mail-la0-f41.google.com (mail-la0-f41.google.com\r
+ [209.85.215.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 4A2EE431FBC\r
+ for <notmuch@notmuchmail.org>; Sun, 3 Mar 2013 13:55:20 -0800 (PST)\r
+Received: by mail-la0-f41.google.com with SMTP id fo12so4440461lab.28\r
+ for <notmuch@notmuchmail.org>; Sun, 03 Mar 2013 13:55:18 -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:cc:subject:date:message-id:x-mailer:in-reply-to\r
+ :references:in-reply-to:references:x-gm-message-state;\r
+ bh=wGaRPvaCRQlvxW/J5c/9raIR6+TSLjAW/ASXq6YhIGs=;\r
+ b=UZODMkm+nIiTl39U+4higi3rVQXoeQsNINxP9ATfR80argyOgHqlyA05ZiMXtEKTSi\r
+ PLu7NLi+C6usYILNz1QtmvfN/VXpkduDsxJfc5UGX4Ks50qOMEu1zbrJq4g0CaGqSLuZ\r
+ BiCIh+/zh5uex3zkhVFKOVRDlLmZptKzQyxOjZFiysLu1OT71RvfMo6HmBSqkkidWOA2\r
+ 8cfjUNIDm4viyxhB572Kb6u23gUWEIT7csZs7dIiYoqlQBpAwNvosqolgOENha+Tkb15\r
+ S9daB3Had8Fw+yv5KSykMsjMO6CTefrNozK0pz1nKxA1/Vlk8iPm/oh5/AIFo3Azai2B\r
+ UyOg==\r
+X-Received: by 10.152.125.239 with SMTP id mt15mr15873485lab.26.1362347718747;\r
+ Sun, 03 Mar 2013 13:55:18 -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 b13sm6611855lbd.10.2013.03.03.13.55.17\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sun, 03 Mar 2013 13:55:17 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/6] cli: plug main notmuch command into subcommand\r
+ machinery\r
+Date: Sun, 3 Mar 2013 23:55:06 +0200\r
+Message-Id:\r
+ <bf81d217ceefc512a252a5acccd3c62b185eb874.1362347362.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <cover.1362347362.git.jani@nikula.org>\r
+References: <cover.1362347362.git.jani@nikula.org>\r
+In-Reply-To: <cover.1362347362.git.jani@nikula.org>\r
+References: <cover.1362347362.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQmq3hzDQCOlvErbDQfgVMIA29Zu//QKRxYDVL0CdCdTCcUKgQFoeWrpZQAOxd6wC5ok2OoI\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: Sun, 03 Mar 2013 21:55:21 -0000\r
+\r
+This allows top level arguments to be added to notmuch in a way that\r
+doesn't require special handling for the plain notmuch command without\r
+a subcommand.\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 3dff6d4..ec2f20f 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
+ notmuch_bool_t is_new;\r
+@@ -256,6 +263,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
+@@ -277,9 +285,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
+@@ -294,10 +299,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