From: Jani Nikula Date: Sun, 3 Mar 2013 21:55:06 +0000 (+0200) Subject: [PATCH v2 2/6] cli: plug main notmuch command into subcommand machinery X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d5bf152507462ce066f49b26485d35689434d706;p=notmuch-archives.git [PATCH v2 2/6] cli: plug main notmuch command into subcommand machinery --- diff --git a/7b/a897ad5d788586a0a02fdfdd7ae11f8aaee6ac b/7b/a897ad5d788586a0a02fdfdd7ae11f8aaee6ac new file mode 100644 index 000000000..7003d84e2 --- /dev/null +++ b/7b/a897ad5d788586a0a02fdfdd7ae11f8aaee6ac @@ -0,0 +1,162 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 0A17B431FAE + for ; Sun, 3 Mar 2013 13:55:21 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id nZT72VodYyjM for ; + Sun, 3 Mar 2013 13:55:20 -0800 (PST) +Received: from mail-la0-f41.google.com (mail-la0-f41.google.com + [209.85.215.41]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 4A2EE431FBC + for ; Sun, 3 Mar 2013 13:55:20 -0800 (PST) +Received: by mail-la0-f41.google.com with SMTP id fo12so4440461lab.28 + for ; Sun, 03 Mar 2013 13:55:18 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to + :references:in-reply-to:references:x-gm-message-state; + bh=wGaRPvaCRQlvxW/J5c/9raIR6+TSLjAW/ASXq6YhIGs=; + b=UZODMkm+nIiTl39U+4higi3rVQXoeQsNINxP9ATfR80argyOgHqlyA05ZiMXtEKTSi + PLu7NLi+C6usYILNz1QtmvfN/VXpkduDsxJfc5UGX4Ks50qOMEu1zbrJq4g0CaGqSLuZ + BiCIh+/zh5uex3zkhVFKOVRDlLmZptKzQyxOjZFiysLu1OT71RvfMo6HmBSqkkidWOA2 + 8cfjUNIDm4viyxhB572Kb6u23gUWEIT7csZs7dIiYoqlQBpAwNvosqolgOENha+Tkb15 + S9daB3Had8Fw+yv5KSykMsjMO6CTefrNozK0pz1nKxA1/Vlk8iPm/oh5/AIFo3Azai2B + UyOg== +X-Received: by 10.152.125.239 with SMTP id mt15mr15873485lab.26.1362347718747; + Sun, 03 Mar 2013 13:55:18 -0800 (PST) +Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. + [80.223.81.27]) + by mx.google.com with ESMTPS id b13sm6611855lbd.10.2013.03.03.13.55.17 + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sun, 03 Mar 2013 13:55:17 -0800 (PST) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH v2 2/6] cli: plug main notmuch command into subcommand + machinery +Date: Sun, 3 Mar 2013 23:55:06 +0200 +Message-Id: + +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: +References: +In-Reply-To: +References: +X-Gm-Message-State: + ALoCoQmq3hzDQCOlvErbDQfgVMIA29Zu//QKRxYDVL0CdCdTCcUKgQFoeWrpZQAOxd6wC5ok2OoI +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 03 Mar 2013 21:55:21 -0000 + +This allows top level arguments to be added to notmuch in a way that +doesn't require special handling for the plain notmuch command without +a subcommand. +--- + notmuch.c | 26 +++++++++++++++++--------- + 1 file changed, 17 insertions(+), 9 deletions(-) + +diff --git a/notmuch.c b/notmuch.c +index 3dff6d4..ec2f20f 100644 +--- a/notmuch.c ++++ b/notmuch.c +@@ -34,7 +34,13 @@ typedef struct command { + static int + notmuch_help_command (void *ctx, int argc, char *argv[]); + ++static int ++notmuch_command (void *ctx, int argc, char *argv[]); ++ + static command_t commands[] = { ++ { NULL, notmuch_command, ++ NULL, ++ "Notmuch main command." }, + { "setup", notmuch_setup_command, + NULL, + "Interactively setup notmuch for first use." }, +@@ -76,7 +82,8 @@ find_command (const char *name) + size_t i; + + for (i = 0; i < ARRAY_SIZE (commands); i++) +- if (strcmp (name, commands[i].name) == 0) ++ if ((!name && !commands[i].name) || ++ (name && commands[i].name && strcmp (name, commands[i].name) == 0)) + return &commands[i]; + + return NULL; +@@ -101,8 +108,8 @@ usage (FILE *out) + for (i = 0; i < ARRAY_SIZE (commands); i++) { + command = &commands[i]; + +- fprintf (out, " %-11s %s\n", +- command->name, command->summary); ++ if (command->name) ++ fprintf (out, " %-11s %s\n", command->name, command->summary); + } + + fprintf (out, "\n"); +@@ -192,7 +199,7 @@ notmuch_help_command (void *ctx, int argc, char *argv[]) + * to be more clever about this in the future. + */ + static int +-notmuch (void *ctx) ++notmuch_command (void *ctx, unused(int argc), unused(char *argv[])) + { + notmuch_config_t *config; + notmuch_bool_t is_new; +@@ -256,6 +263,7 @@ main (int argc, char *argv[]) + { + void *local; + char *talloc_report; ++ const char *command_name = NULL; + command_t *command; + notmuch_bool_t print_help=FALSE, print_version=FALSE; + int opt_index; +@@ -277,9 +285,6 @@ main (int argc, char *argv[]) + /* Globally default to the current output format version. */ + notmuch_format_version = NOTMUCH_FORMAT_CUR; + +- if (argc == 1) +- return notmuch (local); +- + opt_index = parse_arguments (argc, argv, options, 1); + if (opt_index < 0) { + /* diagnostics already printed */ +@@ -294,10 +299,13 @@ main (int argc, char *argv[]) + return 0; + } + +- command = find_command (argv[opt_index]); ++ if (opt_index < argc) ++ command_name = argv[opt_index]; ++ ++ command = find_command (command_name); + if (!command) { + fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n", +- argv[opt_index]); ++ command_name); + return 1; + } + +-- +1.7.10.4 +