[PATCH 2/4] cli: refactor notmuch_help_command
authorDavid Bremner <david@tethera.net>
Tue, 7 Apr 2015 19:30:40 +0000 (04:30 +0900)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:48:46 +0000 (14:48 -0700)
ae/708ead246777b5934233e6c26293d688aad60e [new file with mode: 0644]

diff --git a/ae/708ead246777b5934233e6c26293d688aad60e b/ae/708ead246777b5934233e6c26293d688aad60e
new file mode 100644 (file)
index 0000000..723f522
--- /dev/null
@@ -0,0 +1,129 @@
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id DC4716DE1AEF\r
+ for <notmuch@notmuchmail.org>; Tue,  7 Apr 2015 12:33:05 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.43\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.43 tagged_above=-999 required=5 tests=[AWL=0.420,\r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id r8zJoHXzZA6L for <notmuch@notmuchmail.org>;\r
+ Tue,  7 Apr 2015 12:33:04 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+ [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 0D6236DE1AE1\r
+ for <notmuch@notmuchmail.org>; Tue,  7 Apr 2015 12:33:03 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+ 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1YfZDa-0001xt-EY; Tue, 07 Apr 2015 19:31:26 +0000\r
+Received: (nullmailer pid 16649 invoked by uid 1000); Tue, 07 Apr 2015\r
+ 19:30:49 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: Mark Walters <markwalters1009@gmail.com>, David Bremner\r
+ <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: [PATCH 2/4] cli: refactor notmuch_help_command\r
+Date: Wed,  8 Apr 2015 04:30:40 +0900\r
+Message-Id: <1428435042-16503-3-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1428435042-16503-1-git-send-email-david@tethera.net>\r
+References: <871tjws8w8.fsf@qmul.ac.uk>\r
+ <1428435042-16503-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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, 07 Apr 2015 19:33:06 -0000\r
+\r
+Create a new private entry point _help_for so that we can call help\r
+without simulating a command line invokation to set up the arguments.\r
+---\r
+ notmuch.c | 26 ++++++++++++++++++--------\r
+ 1 file changed, 18 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/notmuch.c b/notmuch.c\r
+index 31672c3..bff941f 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -177,21 +177,19 @@ exec_man (const char *page)\r
+ }\r
\r
+ static int\r
+-notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[])\r
++_help_for (const char *topic_name)\r
+ {\r
+     command_t *command;\r
+     help_topic_t *topic;\r
+     unsigned int i;\r
\r
+-    argc--; argv++; /* Ignore "help" */\r
+-\r
+-    if (argc == 0) {\r
++    if (!topic_name) {\r
+       printf ("The notmuch mail system.\n\n");\r
+       usage (stdout);\r
+       return EXIT_SUCCESS;\r
+     }\r
\r
+-    if (strcmp (argv[0], "help") == 0) {\r
++    if (strcmp (topic_name, "help") == 0) {\r
+       printf ("The notmuch help system.\n\n"\r
+               "\tNotmuch uses the man command to display help. In case\n"\r
+               "\tof difficulties check that MANPATH includes the pages\n"\r
+@@ -200,7 +198,7 @@ notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[]\r
+       return EXIT_SUCCESS;\r
+     }\r
\r
+-    command = find_command (argv[0]);\r
++    command = find_command (topic_name);\r
+     if (command) {\r
+       char *page = talloc_asprintf (NULL, "notmuch-%s", command->name);\r
+       exec_man (page);\r
+@@ -208,7 +206,7 @@ notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[]\r
\r
+     for (i = 0; i < ARRAY_SIZE (help_topics); i++) {\r
+       topic = &help_topics[i];\r
+-      if (strcmp (argv[0], topic->name) == 0) {\r
++      if (strcmp (topic_name, topic->name) == 0) {\r
+           char *page = talloc_asprintf (NULL, "notmuch-%s", topic->name);\r
+           exec_man (page);\r
+       }\r
+@@ -216,10 +214,22 @@ notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[]\r
\r
+     fprintf (stderr,\r
+            "\nSorry, %s is not a known command. There's not much I can do to help.\n\n",\r
+-           argv[0]);\r
++           topic_name);\r
+     return EXIT_FAILURE;\r
+ }\r
\r
++static int\r
++notmuch_help_command (unused (notmuch_config_t * config), int argc, char *argv[])\r
++{\r
++    argc--; argv++; /* Ignore "help" */\r
++\r
++    if (argc == 0) {\r
++      return _help_for (NULL);\r
++    }\r
++\r
++    return _help_for (argv[0]);\r
++}\r
++\r
+ /* Handle the case of "notmuch" being invoked with no command\r
+  * argument. For now we just call notmuch_setup_command, but we plan\r
+  * to be more clever about this in the future.\r
+-- \r
+2.1.4\r
+\r