[PATCH 2/2] cli: convert "notmuch new" to the argument parser
authorJani Nikula <jani@nikula.org>
Mon, 3 Dec 2012 20:56:13 +0000 (22:56 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:23 +0000 (09:51 -0800)
18/e4b2de52eeff304e64798bd3f5f2cee1478725 [new file with mode: 0644]

diff --git a/18/e4b2de52eeff304e64798bd3f5f2cee1478725 b/18/e4b2de52eeff304e64798bd3f5f2cee1478725
new file mode 100644 (file)
index 0000000..403efc5
--- /dev/null
@@ -0,0 +1,159 @@
+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 468C4431FC2\r
+       for <notmuch@notmuchmail.org>; Mon,  3 Dec 2012 12:56:24 -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 Yo1m3Mo5gv9B for <notmuch@notmuchmail.org>;\r
+       Mon,  3 Dec 2012 12:56:23 -0800 (PST)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+       [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id D7261431FB6\r
+       for <notmuch@notmuchmail.org>; Mon,  3 Dec 2012 12:56:22 -0800 (PST)\r
+Received: by mail-lb0-f181.google.com with SMTP id ge1so2880376lbb.26\r
+       for <notmuch@notmuchmail.org>; Mon, 03 Dec 2012 12:56:21 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references\r
+       :in-reply-to:references:x-gm-message-state;\r
+       bh=WjieLvL5Vvd+DqOJBp48Ahgr3TtkaU0A1c8O5KtgoNw=;\r
+       b=PPYyYFc2jVtb5UYSbao7TPoyQ7Hj2DNcnkTGrOXJETp7BSxRGnlqofDoqnU34trzEx\r
+       h4h8SZnBQCIoDsrx8Q8Ifhzf0G23/XJRjeoGF72sHCQmpirrf6lK0BZsBDeWTylNfYlj\r
+       7cbSXPwtKsLqwsYQ7fu3/dGd5DDqwESCLcXNwP6VSqtl0UiPFDJXQSaJa5t290xaMa3W\r
+       1OVOCtS3Q5aMOy4XvSVkm6iFGch+ObsZIkINip/9gzdKACVuO+hutIwUnw/Dxa8/Pk+9\r
+       4lrN82ipBKt2GXAKt/bAScMzpdlYSHOdGC/cLPRoQWkgcgjyrZK455yGxdIu0Sspd9zM\r
+       BCrg==\r
+Received: by 10.152.124.111 with SMTP id mh15mr10745675lab.20.1354568181018;\r
+       Mon, 03 Dec 2012 12:56:21 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe51df00-27.dhcp.inet.fi.\r
+       [80.223.81.27])\r
+       by mx.google.com with ESMTPS id oj5sm5824688lab.8.2012.12.03.12.56.19\r
+       (version=SSLv3 cipher=OTHER); Mon, 03 Dec 2012 12:56:20 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] cli: convert "notmuch new" to the argument parser\r
+Date: Mon,  3 Dec 2012 22:56:13 +0200\r
+Message-Id:\r
+ <e31ac6b2ceed533f8ac5386a010f4c052e09502e.1354568072.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To:\r
+ <c4f2a1048763950dd14e13c99a4e7eb333be8c9d.1354568072.git.jani@nikula.org>\r
+References:\r
+ <c4f2a1048763950dd14e13c99a4e7eb333be8c9d.1354568072.git.jani@nikula.org>\r
+In-Reply-To:\r
+ <c4f2a1048763950dd14e13c99a4e7eb333be8c9d.1354568072.git.jani@nikula.org>\r
+References:\r
+ <c4f2a1048763950dd14e13c99a4e7eb333be8c9d.1354568072.git.jani@nikula.org>\r
+X-Gm-Message-State:\r
+ ALoCoQlRUscPPEoj3fx6iEattPNM0qaNTLfIQi5m5rCg3+1SIq1luy50k2cJWlIoiIY0C0DoB2xj\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: Mon, 03 Dec 2012 20:56:24 -0000\r
+\r
+Use the notmuch argument parser to handle arguments in "notmuch\r
+new". As a side effect, this fixes broken STRNCMP_LITERAL usage that\r
+accepts, for example, --verbosefoo for --verbose.\r
+---\r
+ notmuch-new.c |   38 +++++++++++++++++++-------------------\r
+ 1 file changed, 19 insertions(+), 19 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 718a538..feb9c32 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -36,8 +36,8 @@ typedef struct _filename_list {\r
\r
+ typedef struct {\r
+     int output_is_a_tty;\r
+-    int verbose;\r
+-    int debug;\r
++    notmuch_bool_t verbose;\r
++    notmuch_bool_t debug;\r
+     const char **new_tags;\r
+     size_t new_tags_length;\r
+     const char **new_ignore;\r
+@@ -853,28 +853,28 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+     char *dot_notmuch_path;\r
+     struct sigaction action;\r
+     _filename_node_t *f;\r
++    int opt_index;\r
+     int i;\r
+     notmuch_bool_t timer_is_active = FALSE;\r
+-    notmuch_bool_t run_hooks = TRUE;\r
++    notmuch_bool_t no_hooks = FALSE;\r
\r
+-    add_files_state.verbose = 0;\r
+-    add_files_state.debug = 0;\r
++    add_files_state.verbose = FALSE;\r
++    add_files_state.debug = FALSE;\r
+     add_files_state.output_is_a_tty = isatty (fileno (stdout));\r
\r
+-    argc--; argv++; /* skip subcommand argument */\r
++    notmuch_opt_desc_t options[] = {\r
++      { NOTMUCH_OPT_BOOLEAN,  &add_files_state.verbose, "verbose", 'v', 0 },\r
++      { NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },\r
++      { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },\r
++      { 0, 0, 0, 0, 0 }\r
++    };\r
\r
+-    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
+-      if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
+-          add_files_state.verbose = 1;\r
+-      } else if (strcmp (argv[i], "--debug") == 0) {\r
+-          add_files_state.debug = 1;\r
+-      } else if (strcmp (argv[i], "--no-hooks") == 0) {\r
+-          run_hooks = FALSE;\r
+-      } else {\r
+-          fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
+-          return 1;\r
+-      }\r
++    opt_index = parse_arguments (argc, argv, options, 1);\r
++    if (opt_index < 0) {\r
++      /* diagnostics already printed */\r
++      return 1;\r
+     }\r
++\r
+     config = notmuch_config_open (ctx, NULL, NULL);\r
+     if (config == NULL)\r
+       return 1;\r
+@@ -884,7 +884,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+     add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
+     db_path = notmuch_config_get_database_path (config);\r
\r
+-    if (run_hooks) {\r
++    if (!no_hooks) {\r
+       ret = notmuch_run_hook (db_path, "pre-new");\r
+       if (ret)\r
+           return ret;\r
+@@ -1045,7 +1045,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
\r
+     notmuch_database_destroy (notmuch);\r
\r
+-    if (run_hooks && !ret && !interrupted)\r
++    if (!no_hooks && !ret && !interrupted)\r
+       ret = notmuch_run_hook (db_path, "post-new");\r
\r
+     return ret || interrupted;\r
+-- \r
+1.7.10.4\r
+\r