[PATCH 1/3] cli: add support for parsing multiple keyword arguments
authorJani Nikula <jani@nikula.org>
Sat, 6 Sep 2014 12:53:28 +0000 (15:53 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:04:28 +0000 (10:04 -0800)
cf/709d1f8c7887d3ee8b5bffc1d320c1593e4d7a [new file with mode: 0644]

diff --git a/cf/709d1f8c7887d3ee8b5bffc1d320c1593e4d7a b/cf/709d1f8c7887d3ee8b5bffc1d320c1593e4d7a
new file mode 100644 (file)
index 0000000..48bfb7c
--- /dev/null
@@ -0,0 +1,109 @@
+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 E2299431FB6\r
+       for <notmuch@notmuchmail.org>; Sat,  6 Sep 2014 05:53:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 6AHgVXx+KsPM for <notmuch@notmuchmail.org>;\r
+       Sat,  6 Sep 2014 05:53:37 -0700 (PDT)\r
+Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com\r
+       [209.85.212.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 30321431FBC\r
+       for <notmuch@notmuchmail.org>; Sat,  6 Sep 2014 05:53:37 -0700 (PDT)\r
+Received: by mail-wi0-f180.google.com with SMTP id ex7so609183wid.13\r
+       for <notmuch@notmuchmail.org>; Sat, 06 Sep 2014 05:53:33 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:date:message-id;\r
+       bh=Uq5Jq31quR31nh5r9iX/mSJrDDNveWaNZkrAENfogdM=;\r
+       b=BYt8xdHFG0K2ihWGCm9rKJxl8ynRl/naJYs+VcxxwT+HLjjsETOGM9LgSRBAXSCAfc\r
+       GhJLqNR6am9hKCzndj3e9Hvos6fIBM+ekIqGpe0LERx8y8b78byFQicm2JvlaqtqYUc7\r
+       wJQRzTkJENHvhwv204uE+jEQkVmWL2L37/xK0AqnjhvYDm15kGDUOor9ICxaS52yQ1sl\r
+       fX12ot3r616sEIPhIivdTw5F+6TkCvvio6bL2jlutAf0RQp/LTs6oswHc2nwVMN8ySmZ\r
+       AHfrEW8WPZWheBpAph29ZP3TqUQAcPKqsUMYVFcbWbcwtn2CEpEVCVJsjDb7tSqjH7k3\r
+       omHw==\r
+X-Gm-Message-State:\r
+ ALoCoQnTzIBYoH92qkTbeVPhT33deUAbLOtLA2rREar4BZiwY6hLL9/wvaxtPnGRw9GR6ESnOpxb\r
+X-Received: by 10.180.186.10 with SMTP id fg10mr9898874wic.20.1410008012430;\r
+       Sat, 06 Sep 2014 05:53:32 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c374-75.dhcp.inet.fi.\r
+       [88.195.116.75])\r
+       by mx.google.com with ESMTPSA id r8sm4483908wjy.20.2014.09.06.05.53.31\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Sat, 06 Sep 2014 05:53:31 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/3] cli: add support for parsing multiple keyword arguments\r
+Date: Sat,  6 Sep 2014 15:53:28 +0300\r
+Message-Id: <1410008010-3770-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.0\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, 06 Sep 2014 12:53:43 -0000\r
+\r
+This allows having multiple --foo=bar --foo=baz options on the command\r
+line, with the corresponding values OR'd together.\r
+---\r
+ command-line-arguments.c | 6 +++++-\r
+ command-line-arguments.h | 1 +\r
+ 2 files changed, 6 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/command-line-arguments.c b/command-line-arguments.c\r
+index 844d6c3d18bf..c6f7269603cb 100644\r
+--- a/command-line-arguments.c\r
++++ b/command-line-arguments.c\r
+@@ -23,7 +23,10 @@ _process_keyword_arg (const notmuch_opt_desc_t *arg_desc, char next, const char\r
+     while (keywords->name) {\r
+       if (strcmp (arg_str, keywords->name) == 0) {\r
+           if (arg_desc->output_var) {\r
+-              *((int *)arg_desc->output_var) = keywords->value;\r
++              if (arg_desc->opt_type == NOTMUCH_OPT_KEYWORD_FLAGS)\r
++                  *((int *)arg_desc->output_var) |= keywords->value;\r
++              else\r
++                  *((int *)arg_desc->output_var) = keywords->value;\r
+           }\r
+           return TRUE;\r
+       }\r
+@@ -152,6 +155,7 @@ parse_option (const char *arg,\r
\r
+       switch (try->opt_type) {\r
+       case NOTMUCH_OPT_KEYWORD:\r
++      case NOTMUCH_OPT_KEYWORD_FLAGS:\r
+           return _process_keyword_arg (try, next, value);\r
+       case NOTMUCH_OPT_BOOLEAN:\r
+           return _process_boolean_arg (try, next, value);\r
+diff --git a/command-line-arguments.h b/command-line-arguments.h\r
+index de1734ad2fdb..085a4923b5fa 100644\r
+--- a/command-line-arguments.h\r
++++ b/command-line-arguments.h\r
+@@ -8,6 +8,7 @@ enum notmuch_opt_type {\r
+     NOTMUCH_OPT_BOOLEAN,      /* --verbose              */\r
+     NOTMUCH_OPT_INT,          /* --frob=8               */\r
+     NOTMUCH_OPT_KEYWORD,      /* --format=raw|json|text */\r
++    NOTMUCH_OPT_KEYWORD_FLAGS,  /* the above with values OR'd together */\r
+     NOTMUCH_OPT_STRING,               /* --file=/tmp/gnarf.txt  */\r
+     NOTMUCH_OPT_POSITION      /* notmuch dump pos_arg   */\r
+ };\r
+-- \r
+2.1.0\r
+\r