From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id CD430431FAE for ; Tue, 29 Jan 2013 13:47:02 -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 wt6ZMJb2I2ze for ; Tue, 29 Jan 2013 13:47:01 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 2417E431FDB for ; Tue, 29 Jan 2013 13:46:55 -0800 (PST) Received: by mail-lb0-f182.google.com with SMTP id gg6so1345585lbb.13 for ; Tue, 29 Jan 2013 13:46:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:x-gm-message-state; bh=uhL2LZNjBb0n5brjrnx0H08GMZdz6QacbnD+fdoOBbU=; b=PSJpy3JNUhG0gHW8R1k17ZWT8bH57Bq5X/Jf1UrRr/bG2F+63cS56EDwydW6WhTJ1m /9n9lucxEZkQuq5rkOvi8a9MM//nXelqtfDyHedwcGIrHSzv8U/9fVSa0UjF+kC/npLc hFujV7nzJHNVuXLamws9PEX1MkK3JzR1OaAbUwCXQs8/CJm5FTmeh79/KhT56gRYRmlZ h+DokuZ/euMBlykOQ6Q1oQ8p7Fq6vgL+o7NUcNCe0xMt2zmnhpAzld9fqSn6uofdF+Fo //2QbppDfNHSGLLznKnTUr9xDl90jvtQn142dLgKJPahv5W19xt6Ojsjf7lNiSM4WPe3 RG+g== X-Received: by 10.112.48.130 with SMTP id l2mr1036206lbn.44.1359496013145; Tue, 29 Jan 2013 13:46:53 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-50df51-27.dhcp.inet.fi. [80.223.81.27]) by mx.google.com with ESMTPS id f8sm5597960lbg.2.2013.01.29.13.46.50 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 29 Jan 2013 13:46:52 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH 4/6] cli: plug main notmuch command into subcommand machinery Date: Tue, 29 Jan 2013 23:46:22 +0200 Message-Id: X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQmgBoKO3ZmBScS0a/lkLZAVeqS4wAASF/THun6FW89UYUqbwe/jp9XQV71Zu30zsCtkeG/O 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: Tue, 29 Jan 2013 21:47:03 -0000 This also allows the main notmuch command to have arguments (though they are not used). --- notmuch.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/notmuch.c b/notmuch.c index c47b998..67d5772 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; char *db_path; @@ -255,6 +262,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; @@ -276,9 +284,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 */ @@ -293,10 +298,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