From 8cd105c6f36f598fc2ce6409df330e081855deb8 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Mon, 6 Apr 2015 05:59:32 +0900 Subject: [PATCH] [PATCH 2/4] cli: refactor notmuch_help_command --- d1/f62d7b74a55e6f7de941e49224f98e0e5dd19d | 129 ++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 d1/f62d7b74a55e6f7de941e49224f98e0e5dd19d diff --git a/d1/f62d7b74a55e6f7de941e49224f98e0e5dd19d b/d1/f62d7b74a55e6f7de941e49224f98e0e5dd19d new file mode 100644 index 000000000..218ff6879 --- /dev/null +++ b/d1/f62d7b74a55e6f7de941e49224f98e0e5dd19d @@ -0,0 +1,129 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id C81556DE1B43 + for ; Sun, 5 Apr 2015 14:33:24 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.67 +X-Spam-Level: +X-Spam-Status: No, score=0.67 tagged_above=-999 required=5 tests=[AWL=0.660, + T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id U22E_QsMuFQl for ; + Sun, 5 Apr 2015 14:33:22 -0700 (PDT) +X-Greylist: delayed 1942 seconds by postgrey-1.35 at arlo; + Sun, 05 Apr 2015 14:33:22 PDT +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id 405A36DE1B42 + for ; Sun, 5 Apr 2015 14:33:22 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1Yerfi-0002Ru-TG; Sun, 05 Apr 2015 21:01:34 +0000 +Received: (nullmailer pid 29562 invoked by uid 1000); Sun, 05 Apr 2015 + 21:00:40 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH 2/4] cli: refactor notmuch_help_command +Date: Mon, 6 Apr 2015 05:59:32 +0900 +Message-Id: <1428267574-28797-3-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1428267574-28797-1-git-send-email-david@tethera.net> +References: <1428267574-28797-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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, 05 Apr 2015 21:33:24 -0000 + +Create a new private entry point _help_for so that we can call help +without simulating a command line invokation to set up the arguments. +--- + notmuch.c | 26 ++++++++++++++++++-------- + 1 file changed, 18 insertions(+), 8 deletions(-) + +diff --git a/notmuch.c b/notmuch.c +index 31672c3..bff941f 100644 +--- a/notmuch.c ++++ b/notmuch.c +@@ -177,21 +177,19 @@ exec_man (const char *page) + } + + static int +-notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[]) ++_help_for (const char *topic_name) + { + command_t *command; + help_topic_t *topic; + unsigned int i; + +- argc--; argv++; /* Ignore "help" */ +- +- if (argc == 0) { ++ if (!topic_name) { + printf ("The notmuch mail system.\n\n"); + usage (stdout); + return EXIT_SUCCESS; + } + +- if (strcmp (argv[0], "help") == 0) { ++ if (strcmp (topic_name, "help") == 0) { + printf ("The notmuch help system.\n\n" + "\tNotmuch uses the man command to display help. In case\n" + "\tof difficulties check that MANPATH includes the pages\n" +@@ -200,7 +198,7 @@ notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[] + return EXIT_SUCCESS; + } + +- command = find_command (argv[0]); ++ command = find_command (topic_name); + if (command) { + char *page = talloc_asprintf (NULL, "notmuch-%s", command->name); + exec_man (page); +@@ -208,7 +206,7 @@ notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[] + + for (i = 0; i < ARRAY_SIZE (help_topics); i++) { + topic = &help_topics[i]; +- if (strcmp (argv[0], topic->name) == 0) { ++ if (strcmp (topic_name, topic->name) == 0) { + char *page = talloc_asprintf (NULL, "notmuch-%s", topic->name); + exec_man (page); + } +@@ -216,10 +214,22 @@ notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[] + + fprintf (stderr, + "\nSorry, %s is not a known command. There's not much I can do to help.\n\n", +- argv[0]); ++ topic_name); + return EXIT_FAILURE; + } + ++static int ++notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[]) ++{ ++ argc--; argv++; /* Ignore "help" */ ++ ++ if (argc == 0) { ++ return _help_for (NULL); ++ } ++ ++ return _help_for (argv[0]); ++} ++ + /* Handle the case of "notmuch" being invoked with no command + * argument. For now we just call notmuch_setup_command, but we plan + * to be more clever about this in the future. +-- +2.1.4 + -- 2.26.2