[Patch v8 1/6] cli: command line parsing: allow default for keyword options
authorMark Walters <markwalters1009@gmail.com>
Sat, 16 Jun 2012 10:21:42 +0000 (11:21 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:41 +0000 (09:47 -0800)
de/f5f0756f95181495cf5d384fdfeb2a333ad620 [new file with mode: 0644]

diff --git a/de/f5f0756f95181495cf5d384fdfeb2a333ad620 b/de/f5f0756f95181495cf5d384fdfeb2a333ad620
new file mode 100644 (file)
index 0000000..3e3f600
--- /dev/null
@@ -0,0 +1,126 @@
+Return-Path: <markwalters1009@gmail.com>\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 47BDF431FAE\r
+       for <notmuch@notmuchmail.org>; Sat, 16 Jun 2012 03:22:05 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       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 4PvYuAL2QCtf for <notmuch@notmuchmail.org>;\r
+       Sat, 16 Jun 2012 03:22:04 -0700 (PDT)\r
+Received: from mail-wi0-f179.google.com (mail-wi0-f179.google.com\r
+       [209.85.212.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id A023B431FB6\r
+       for <notmuch@notmuchmail.org>; Sat, 16 Jun 2012 03:22:04 -0700 (PDT)\r
+Received: by wibhr14 with SMTP id hr14so238325wib.2\r
+       for <notmuch@notmuchmail.org>; Sat, 16 Jun 2012 03:22:03 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=ba2TXiOJxZGeViEVJJ/ucZP1tFS2i3Nle6Yh8ac+HJk=;\r
+       b=C2Qso/piHzdXf9qMEk6by0vVYXG01JFkonPwYDwzSCoxPrgLNh9ktKlQxKhWj4tdB3\r
+       2vmI/u3qtVVsQjGhg74cpTlkjfY2bLWIgmAvllfJSBWMfX1vqHYHerh3p68HbZcGQSUf\r
+       1jAMNfg+CrIrEfgpFgu4v3Ai70JaW22qonknf5FWK9gixxbsPd/J4GQcjsFpznIK4Lur\r
+       4NfvbyAA/SvK42yGx4GH5PaISGzz1CSvvQBfYmIPh6+NP1f45eJ4I4gvSUndvhT1vXDs\r
+       pn/FuZ1wX/zMCdmwM4/IogiDYnhg2GdaYZhV6dsWrWJg83Wc55g6fPCQhGejNXYLqDLW\r
+       pYRg==\r
+Received: by 10.216.213.143 with SMTP id a15mr5157705wep.156.1339842123201;\r
+       Sat, 16 Jun 2012 03:22:03 -0700 (PDT)\r
+Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
+ [94.192.233.223])     by mx.google.com with ESMTPS id\r
+ hv7sm16617138wib.0.2012.06.16.03.22.01        (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sat, 16 Jun 2012 03:22:02 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v8 1/6] cli: command line parsing: allow default for keyword\r
+       options\r
+Date: Sat, 16 Jun 2012 11:21:42 +0100\r
+Message-Id: <1339842107-10632-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1339842107-10632-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1339842107-10632-1-git-send-email-markwalters1009@gmail.com>\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: Sat, 16 Jun 2012 10:22:05 -0000\r
+\r
+This changes the parsing for "keyword" options so that if the option\r
+is specified with no argument the argument is parsed as if it were\r
+passed an empty string. This make it easier to add options to existing\r
+boolean arguments (the existing --option can default to TRUE).\r
+---\r
+ command-line-arguments.c |   17 +++++++++++++----\r
+ 1 files changed, 13 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/command-line-arguments.c b/command-line-arguments.c\r
+index 76b185f..b0a0dab 100644\r
+--- a/command-line-arguments.c\r
++++ b/command-line-arguments.c\r
+@@ -11,10 +11,15 @@\r
+ */\r
\r
+ static notmuch_bool_t\r
+-_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {\r
++_process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char *arg_str) {\r
\r
+     const notmuch_keyword_t *keywords = arg_desc->keywords;\r
\r
++    if (next == 0) {\r
++      /* No keyword given */\r
++      arg_str = "";\r
++    }\r
++\r
+     while (keywords->name) {\r
+       if (strcmp (arg_str, keywords->name) == 0) {\r
+           if (arg_desc->output_var) {\r
+@@ -24,7 +29,10 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, const char *arg_str) {\r
+       }\r
+       keywords++;\r
+     }\r
+-    fprintf (stderr, "unknown keyword: %s\n", arg_str);\r
++    if (next != 0)\r
++      fprintf (stderr, "unknown keyword: %s\n", arg_str);\r
++    else\r
++      fprintf (stderr, "option %s needs a keyword\n", arg_desc->name);\r
+     return FALSE;\r
+ }\r
\r
+@@ -99,7 +107,8 @@ parse_option (const char *arg,\r
+            */\r
+           if (next != '=' && next != ':' && next != 0) return FALSE;\r
+           if (next == 0) {\r
+-              if (try->opt_type != NOTMUCH_OPT_BOOLEAN)\r
++              if (try->opt_type != NOTMUCH_OPT_BOOLEAN &&\r
++                  try->opt_type != NOTMUCH_OPT_KEYWORD)\r
+                   return FALSE;\r
+           } else {\r
+               if (value[0] == 0) return FALSE;\r
+@@ -110,7 +119,7 @@ parse_option (const char *arg,\r
\r
+           switch (try->opt_type) {\r
+           case NOTMUCH_OPT_KEYWORD:\r
+-              return _process_keyword_arg (try, value);\r
++              return _process_keyword_arg (try, next, value);\r
+               break;\r
+           case NOTMUCH_OPT_BOOLEAN:\r
+               return _process_boolean_arg (try, next, value);\r
+-- \r
+1.7.9.1\r
+\r