[RFC PATCH 1/2] cli: add support for hierarchical command line option arrays
authorJani Nikula <jani@nikula.org>
Sat, 1 Nov 2014 11:30:47 +0000 (13:30 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:06:03 +0000 (10:06 -0800)
46/1fb489d4a62312a9abcdf2c04ce4d8a9e28945 [new file with mode: 0644]

diff --git a/46/1fb489d4a62312a9abcdf2c04ce4d8a9e28945 b/46/1fb489d4a62312a9abcdf2c04ce4d8a9e28945
new file mode 100644 (file)
index 0000000..b0dbb02
--- /dev/null
@@ -0,0 +1,122 @@
+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 215E1431FDE\r
+       for <notmuch@notmuchmail.org>; Sat,  1 Nov 2014 04:30:59 -0700 (PDT)\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 MJrBvAGwOU0R for <notmuch@notmuchmail.org>;\r
+       Sat,  1 Nov 2014 04:30:55 -0700 (PDT)\r
+Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
+       [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C0773431FD0\r
+       for <notmuch@notmuchmail.org>; Sat,  1 Nov 2014 04:30:54 -0700 (PDT)\r
+Received: by mail-wi0-f173.google.com with SMTP id n3so3147193wiv.6\r
+       for <notmuch@notmuchmail.org>; Sat, 01 Nov 2014 04:30:53 -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:in-reply-to\r
+       :references:in-reply-to:references;\r
+       bh=g7cnwjxUcYpCo/Qdphgdt1n1EDzuqstDj1y8AevAUHw=;\r
+       b=YnZi0hlLvdJMksfDQ2OhXo1OX430WwcCsM1vUZwME8IhK95W8sSI1fLbZRChQ/Qd22\r
+       VJs1LTUSZxcVUJAOCEJZs9Q2wminLn9h+sIdVshha5Xa4qUui6dQrLobptS1Aje+UTKf\r
+       1Y0pgmKd873yJ5/5hqvU14pCWIcVvPUa84YypWfI/PiSAbeqU2K/WfiP6ByKuZ7TP/L/\r
+       HTb4YgWreC4Q5pJTS0dNNFp71pEFwIs/qI2FUgwn88Z3ymKV9Aq3A2JtfXUZ/ZHVFQnz\r
+       VacpeEp5+xOwlfihvdfKSYjgvdZN7kWa14PW4L2ZSxbdrGMEM2phMnBPlNYoZNCCi8dG\r
+       +49Q==\r
+X-Gm-Message-State:\r
+ ALoCoQkkfwZSF5tlzf6dZw1IELyQHT31S/EgfScQIuGlxgYtvoIChnqL9YbBJpNwyohpIRrsQqRm\r
+X-Received: by 10.180.106.104 with SMTP id gt8mr3317542wib.51.1414841453728;\r
+       Sat, 01 Nov 2014 04:30:53 -0700 (PDT)\r
+Received: from localhost (dsl-hkibrasgw2-58c36d-48.dhcp.inet.fi.\r
+       [88.195.109.48]) by mx.google.com with ESMTPSA id\r
+       gg18sm1657240wic.21.2014.11.01.04.30.52 for <multiple recipients>\r
+       (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+       Sat, 01 Nov 2014 04:30:53 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Michal Sojka <sojkam1@fel.cvut.cz>\r
+Subject: [RFC PATCH 1/2] cli: add support for hierarchical command line option\r
+       arrays\r
+Date: Sat,  1 Nov 2014 13:30:47 +0200\r
+Message-Id:\r
+ <b63d5006bffad50dead14bdfdaf0529911807fa9.1414839970.git.jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <cover.1414839970.git.jani@nikula.org>\r
+References: <87egtn2s4z.fsf@steelpick.2x.cz>\r
+       <cover.1414839970.git.jani@nikula.org>\r
+In-Reply-To: <cover.1414839970.git.jani@nikula.org>\r
+References: <cover.1414839970.git.jani@nikula.org>\r
+Cc: notmuch@notmuchmail.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: Sat, 01 Nov 2014 11:30:59 -0000\r
+\r
+NOTMUCH_OPT_INHERIT expects a notmuch_opt_desc_t * pointer in\r
+output_var.\r
+---\r
+ command-line-arguments.c | 11 +++++++----\r
+ command-line-arguments.h |  1 +\r
+ 2 files changed, 8 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/command-line-arguments.c b/command-line-arguments.c\r
+index c6f7269603cb..eb977d0a6fa9 100644\r
+--- a/command-line-arguments.c\r
++++ b/command-line-arguments.c\r
+@@ -122,16 +122,19 @@ parse_position_arg (const char *arg_str, int pos_arg_index,\r
+  */\r
\r
+ notmuch_bool_t\r
+-parse_option (const char *arg,\r
+-            const notmuch_opt_desc_t *options) {\r
++parse_option (const char *_arg, const notmuch_opt_desc_t *options)\r
++{\r
++    const char *arg = _arg + 2; /* _arg starts with -- */\r
\r
+     assert(arg);\r
+     assert(options);\r
\r
+-    arg += 2;\r
+-\r
+     const notmuch_opt_desc_t *try;\r
+     for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) {\r
++      if (try->opt_type == NOTMUCH_OPT_INHERIT &&\r
++          parse_option (_arg, try->output_var))\r
++          return TRUE;\r
++\r
+       if (! try->name)\r
+           continue;\r
\r
+diff --git a/command-line-arguments.h b/command-line-arguments.h\r
+index 6444129ad2d0..309aaf2b37b8 100644\r
+--- a/command-line-arguments.h\r
++++ b/command-line-arguments.h\r
+@@ -5,6 +5,7 @@\r
\r
+ enum notmuch_opt_type {\r
+     NOTMUCH_OPT_END = 0,\r
++    NOTMUCH_OPT_INHERIT,      /* another options table */\r
+     NOTMUCH_OPT_BOOLEAN,      /* --verbose              */\r
+     NOTMUCH_OPT_INT,          /* --frob=8               */\r
+     NOTMUCH_OPT_KEYWORD,      /* --format=raw|json|text */\r
+-- \r
+2.1.1\r
+\r