[PATCH 2/4] cli: convert "notmuch reply" to use the new argument parser
authorJani Nikula <jani@nikula.org>
Thu, 5 Jan 2012 20:25:13 +0000 (22:25 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:38 +0000 (09:41 -0800)
63/ba8def433dbd195017b0d78380e7a7de325d26 [new file with mode: 0644]

diff --git a/63/ba8def433dbd195017b0d78380e7a7de325d26 b/63/ba8def433dbd195017b0d78380e7a7de325d26
new file mode 100644 (file)
index 0000000..43bb4da
--- /dev/null
@@ -0,0 +1,172 @@
+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 14AAD42116D\r
+       for <notmuch@notmuchmail.org>; Thu,  5 Jan 2012 12:25:29 -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 jMxWmehpqxhb for <notmuch@notmuchmail.org>;\r
+       Thu,  5 Jan 2012 12:25:27 -0800 (PST)\r
+Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
+ [74.125.83.53])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 2275F429E3B   for <notmuch@notmuchmail.org>; Thu,  5 Jan 2012 12:25:27 -0800\r
+ (PST)\r
+Received: by mail-ee0-f53.google.com with SMTP id d41so756745eek.26\r
+       for <notmuch@notmuchmail.org>; Thu, 05 Jan 2012 12:25:26 -0800 (PST)\r
+Received: by 10.14.22.10 with SMTP id s10mr1232481ees.122.1325795126730;\r
+       Thu, 05 Jan 2012 12:25:26 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
+       [80.220.92.23])\r
+       by mx.google.com with ESMTPS id s16sm238060005eef.2.2012.01.05.12.25.24\r
+       (version=SSLv3 cipher=OTHER); Thu, 05 Jan 2012 12:25:25 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org,\r
+       david@tethera.net\r
+Subject: [PATCH 2/4] cli: convert "notmuch reply" to use the new argument\r
+       parser\r
+Date: Thu,  5 Jan 2012 22:25:13 +0200\r
+Message-Id:\r
+ <74f31cf0b3dc11b365a3838a44f095326d6c9f99.1325794371.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <cover.1325794371.git.jani@nikula.org>\r
+References: <cover.1325794371.git.jani@nikula.org>\r
+In-Reply-To: <cover.1325794371.git.jani@nikula.org>\r
+References: <cover.1325794371.git.jani@nikula.org>\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: Thu, 05 Jan 2012 20:25:29 -0000\r
+\r
+Use the new notmuch argument parser to handle arguments in "notmuch\r
+reply". There should be no functional changes.\r
+\r
+Signed-off-by: Jani Nikula <jani@nikula.org>\r
+---\r
+ notmuch-reply.c |   75 +++++++++++++++++++++++++++----------------------------\r
+ 1 files changed, 37 insertions(+), 38 deletions(-)\r
+\r
+diff --git a/notmuch-reply.c b/notmuch-reply.c\r
+index 1f33a86..000f6da 100644\r
+--- a/notmuch-reply.c\r
++++ b/notmuch-reply.c\r
+@@ -612,62 +612,61 @@ notmuch_reply_format_headers_only(void *ctx,\r
+     return 0;\r
+ }\r
\r
++enum {\r
++    FORMAT_DEFAULT,\r
++    FORMAT_HEADERS_ONLY,\r
++};\r
++\r
+ int\r
+ notmuch_reply_command (void *ctx, int argc, char *argv[])\r
+ {\r
+     notmuch_config_t *config;\r
+     notmuch_database_t *notmuch;\r
+     notmuch_query_t *query;\r
+-    char *opt, *query_string;\r
+-    int i, ret = 0;\r
++    char *query_string;\r
++    int opt_index, ret = 0;\r
+     int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params);\r
+     notmuch_show_params_t params = { .part = -1 };\r
++    int format = FORMAT_DEFAULT;\r
++    notmuch_bool_t decrypt = FALSE;\r
++\r
++    notmuch_opt_desc_t options[] = {\r
++      { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',\r
++        (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },\r
++                                { "headers-only", FORMAT_HEADERS_ONLY },\r
++                                { 0, 0 } } },\r
++      { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 },\r
++      { 0, 0, 0, 0, 0 }\r
++    };\r
\r
+-    reply_format_func = notmuch_reply_format_default;\r
+-\r
+-    argc--; argv++; /* skip subcommand argument */\r
++    opt_index = parse_arguments (argc, argv, options, 1);\r
++    if (opt_index < 0) {\r
++      /* diagnostics already printed */\r
++      return 1;\r
++    }\r
\r
+-    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
+-      if (strcmp (argv[i], "--") == 0) {\r
+-          i++;\r
+-          break;\r
+-      }\r
+-        if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
+-          opt = argv[i] + sizeof ("--format=") - 1;\r
+-          if (strcmp (opt, "default") == 0) {\r
+-              reply_format_func = notmuch_reply_format_default;\r
+-          } else if (strcmp (opt, "headers-only") == 0) {\r
+-              reply_format_func = notmuch_reply_format_headers_only;\r
+-          } else {\r
+-              fprintf (stderr, "Invalid value for --format: %s\n", opt);\r
+-              return 1;\r
+-          }\r
+-      } else if ((STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {\r
+-          if (params.cryptoctx == NULL) {\r
+-              GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);\r
+-              if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg"))) {\r
+-                  fprintf (stderr, "Failed to construct gpg context.\n");\r
+-              } else {\r
+-                  params.decrypt = TRUE;\r
+-                  g_mime_gpg_context_set_always_trust((GMimeGpgContext*)params.cryptoctx, FALSE);\r
+-              }\r
+-              g_object_unref (session);\r
+-              session = NULL;\r
+-          }\r
++    if (format == FORMAT_HEADERS_ONLY)\r
++      reply_format_func = notmuch_reply_format_headers_only;\r
++    else\r
++      reply_format_func = notmuch_reply_format_default;\r
++\r
++    if (decrypt) {\r
++      GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
++      params.cryptoctx = g_mime_gpg_context_new (session, "gpg");\r
++      if (params.cryptoctx) {\r
++          g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) params.cryptoctx, FALSE);\r
++          params.decrypt = TRUE;\r
+       } else {\r
+-          fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
+-          return 1;\r
++          fprintf (stderr, "Failed to construct gpg context.\n");\r
+       }\r
++      g_object_unref (session);\r
+     }\r
\r
+-    argc -= i;\r
+-    argv += i;\r
+-\r
+     config = notmuch_config_open (ctx, NULL, NULL);\r
+     if (config == NULL)\r
+       return 1;\r
\r
+-    query_string = query_string_from_args (ctx, argc, argv);\r
++    query_string = query_string_from_args (ctx, argc-opt_index, argv+opt_index);\r
+     if (query_string == NULL) {\r
+       fprintf (stderr, "Out of memory\n");\r
+       return 1;\r
+-- \r
+1.7.5.4\r
+\r