From: Jani Nikula Date: Sat, 1 Nov 2014 11:30:47 +0000 (+0200) Subject: [RFC PATCH 1/2] cli: add support for hierarchical command line option arrays X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=295dbbeee832e5ba7b44ba02872f787d20283a31;p=notmuch-archives.git [RFC PATCH 1/2] cli: add support for hierarchical command line option arrays --- diff --git a/46/1fb489d4a62312a9abcdf2c04ce4d8a9e28945 b/46/1fb489d4a62312a9abcdf2c04ce4d8a9e28945 new file mode 100644 index 000000000..b0dbb0200 --- /dev/null +++ b/46/1fb489d4a62312a9abcdf2c04ce4d8a9e28945 @@ -0,0 +1,122 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 215E1431FDE + for ; Sat, 1 Nov 2014 04:30:59 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id MJrBvAGwOU0R for ; + Sat, 1 Nov 2014 04:30:55 -0700 (PDT) +Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com + [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id C0773431FD0 + for ; Sat, 1 Nov 2014 04:30:54 -0700 (PDT) +Received: by mail-wi0-f173.google.com with SMTP id n3so3147193wiv.6 + for ; Sat, 01 Nov 2014 04:30:53 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=g7cnwjxUcYpCo/Qdphgdt1n1EDzuqstDj1y8AevAUHw=; + b=YnZi0hlLvdJMksfDQ2OhXo1OX430WwcCsM1vUZwME8IhK95W8sSI1fLbZRChQ/Qd22 + VJs1LTUSZxcVUJAOCEJZs9Q2wminLn9h+sIdVshha5Xa4qUui6dQrLobptS1Aje+UTKf + 1Y0pgmKd873yJ5/5hqvU14pCWIcVvPUa84YypWfI/PiSAbeqU2K/WfiP6ByKuZ7TP/L/ + HTb4YgWreC4Q5pJTS0dNNFp71pEFwIs/qI2FUgwn88Z3ymKV9Aq3A2JtfXUZ/ZHVFQnz + VacpeEp5+xOwlfihvdfKSYjgvdZN7kWa14PW4L2ZSxbdrGMEM2phMnBPlNYoZNCCi8dG + +49Q== +X-Gm-Message-State: + ALoCoQkkfwZSF5tlzf6dZw1IELyQHT31S/EgfScQIuGlxgYtvoIChnqL9YbBJpNwyohpIRrsQqRm +X-Received: by 10.180.106.104 with SMTP id gt8mr3317542wib.51.1414841453728; + Sat, 01 Nov 2014 04:30:53 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c36d-48.dhcp.inet.fi. + [88.195.109.48]) by mx.google.com with ESMTPSA id + gg18sm1657240wic.21.2014.11.01.04.30.52 for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sat, 01 Nov 2014 04:30:53 -0700 (PDT) +From: Jani Nikula +To: Michal Sojka +Subject: [RFC PATCH 1/2] cli: add support for hierarchical command line option + arrays +Date: Sat, 1 Nov 2014 13:30:47 +0200 +Message-Id: + +X-Mailer: git-send-email 2.1.1 +In-Reply-To: +References: <87egtn2s4z.fsf@steelpick.2x.cz> + +In-Reply-To: +References: +Cc: notmuch@notmuchmail.org +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 01 Nov 2014 11:30:59 -0000 + +NOTMUCH_OPT_INHERIT expects a notmuch_opt_desc_t * pointer in +output_var. +--- + command-line-arguments.c | 11 +++++++---- + command-line-arguments.h | 1 + + 2 files changed, 8 insertions(+), 4 deletions(-) + +diff --git a/command-line-arguments.c b/command-line-arguments.c +index c6f7269603cb..eb977d0a6fa9 100644 +--- a/command-line-arguments.c ++++ b/command-line-arguments.c +@@ -122,16 +122,19 @@ parse_position_arg (const char *arg_str, int pos_arg_index, + */ + + notmuch_bool_t +-parse_option (const char *arg, +- const notmuch_opt_desc_t *options) { ++parse_option (const char *_arg, const notmuch_opt_desc_t *options) ++{ ++ const char *arg = _arg + 2; /* _arg starts with -- */ + + assert(arg); + assert(options); + +- arg += 2; +- + const notmuch_opt_desc_t *try; + for (try = options; try->opt_type != NOTMUCH_OPT_END; try++) { ++ if (try->opt_type == NOTMUCH_OPT_INHERIT && ++ parse_option (_arg, try->output_var)) ++ return TRUE; ++ + if (! try->name) + continue; + +diff --git a/command-line-arguments.h b/command-line-arguments.h +index 6444129ad2d0..309aaf2b37b8 100644 +--- a/command-line-arguments.h ++++ b/command-line-arguments.h +@@ -5,6 +5,7 @@ + + enum notmuch_opt_type { + NOTMUCH_OPT_END = 0, ++ NOTMUCH_OPT_INHERIT, /* another options table */ + NOTMUCH_OPT_BOOLEAN, /* --verbose */ + NOTMUCH_OPT_INT, /* --frob=8 */ + NOTMUCH_OPT_KEYWORD, /* --format=raw|json|text */ +-- +2.1.1 +