From: Jani Nikula Date: Fri, 9 Mar 2012 00:48:35 +0000 (+0200) Subject: Re: [PATCH 0/2] cli: Parsing. Add option NOTMUCH_OPT_INT_OR_BOOLEAN X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=f249e4617805a8be9f2adbd232bd2153e3a024b8;p=notmuch-archives.git Re: [PATCH 0/2] cli: Parsing. Add option NOTMUCH_OPT_INT_OR_BOOLEAN --- diff --git a/5a/3e0e590578e28c9d53bf52afbf47d85b38bb13 b/5a/3e0e590578e28c9d53bf52afbf47d85b38bb13 new file mode 100644 index 000000000..4c53d0131 --- /dev/null +++ b/5a/3e0e590578e28c9d53bf52afbf47d85b38bb13 @@ -0,0 +1,127 @@ +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 5D5E0431FB6 + for ; Thu, 8 Mar 2012 16:48:44 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +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 xw0mLNyia2CO for ; + Thu, 8 Mar 2012 16:48:43 -0800 (PST) +Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com + [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 7669D431FAE + for ; Thu, 8 Mar 2012 16:48:43 -0800 (PST) +Received: by lahc1 with SMTP id c1so1165104lah.26 + for ; Thu, 08 Mar 2012 16:48:40 -0800 (PST) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=from:to:subject:in-reply-to:references:user-agent:date:message-id + :mime-version:content-type:x-gm-message-state; + bh=OEtb7ZIev9W+R+BNTQRVBycCS/8lS0CyXNP57l5Uxjs=; + b=CNlnSKrxRWGMnKLDMzIHUt5foUC/6tdVeRbTO1fUe9Nw/F61587WM6CIREH/QH0eVi + +gdiZoIYxEO5gnJ6JXDxv0/dyuvS80uQNhJhLh61WRHB0INySzP9QJoZD5uZU0IUo3uN + 4X36UasGThhV355RXri6AxKvmRXemgSZOA7awxe0A9VnNIOR49/Mun3z3rIF90e+OUcH + dRAHWHjsqsCUDuZRxGGLLr0zeHTqe3AOopgJR8Lq8PZJNagAj8gopgsfaY/hzO3Nbagc + O2n4ZIGLrotsRbLeN3RUhjvzC4Fi0Bcrk3VTUp/DufMNXJPQdgBxXkrRPJhRs2Zo6e0w + NwqQ== +Received: by 10.112.47.161 with SMTP id e1mr100575lbn.42.1331254120312; + Thu, 08 Mar 2012 16:48:40 -0800 (PST) +Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi. + [84.248.80.253]) + by mx.google.com with ESMTPS id p9sm4315364lbw.10.2012.03.08.16.48.37 + (version=SSLv3 cipher=OTHER); Thu, 08 Mar 2012 16:48:38 -0800 (PST) +From: Jani Nikula +To: Mark Walters , notmuch@notmuchmail.org +Subject: Re: [PATCH 0/2] cli: Parsing. Add option NOTMUCH_OPT_INT_OR_BOOLEAN +In-Reply-To: <1331244944-7960-1-git-send-email-markwalters1009@gmail.com> +References: <1331244944-7960-1-git-send-email-markwalters1009@gmail.com> +User-Agent: Notmuch/0.11.1+295~g780f284 (http://notmuchmail.org) Emacs/23.3.1 + (i686-pc-linux-gnu) +Date: Fri, 09 Mar 2012 02:48:35 +0200 +Message-ID: <87lina8uqk.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Gm-Message-State: + ALoCoQnhkiMV0N+Y0j0cvS0egUJSXr7GVgJJMMm2k3nvQ9V4ll4z4NHDrVfFdauxSCCIEG5eSPIS +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: Fri, 09 Mar 2012 00:48:44 -0000 + +On Thu, 8 Mar 2012 22:15:42 +0000, Mark Walters wrote: +> The first patch adds a new command line parsing option +> NOTMUCH_OPT_INT_OR_BOOLEAN for command line parsing which accepts +> --verbose=3 and --verbose with the latter setting verbose to 1. It +> also allows --verbose=0 so (with a little caller support) the user can +> turn off boolean options. +> +> It also means that extra options can be added to the command line +> programs in a backwards compatible manner (e.g. if --verbose already +> exists we could add --verbose=2). +> +> The second patch uses this to make the --entire-thread option to +> notmuch-show a NOTMUCH_OPT_INT_OR_BOOLEAN. In particular this allows +> the caller to disable --entire-thread (with --entire-thread=0) when +> format=json. + +I'm afraid I find both of the patches a bit hacky. The first because +it's more about optional arguments to options than int-or-bool. The +second because it's more about detecting whether the user has provided +an option than int-or-bool. + +For booleans, I think the notmuch style would be to allow --foo=true and +--foo=false in addition to just --foo (which implies true) so you could +also disable booleans. I think this would be fairly simple to implement, +and would require no changes to option parser users. + +With --entire-thread the bigger problem is detecting whether the option +was specified by the user or not. It would be great if the option parser +could provide this information, but it might take a while to get +there... In the mean time, I think I would rather see a well commented +local hack here initializing the notmuch_bool_t params.entire_thread to +-1, and changing it to TRUE or FALSE if not already done so by +parse_arguments(). + + +BR, +Jani. + + +> +> Best wishes +> +> Mark +> +> Mark Walters (2): +> cli: Parsing. Add option NOTMUCH_OPT_INT_OR_BOOLEAN +> cli: make --entire-thread option notmuch-show.c INT_OR_BOOLEAN +> +> command-line-arguments.c | 29 +++++++++++++++++++++++++++-- +> command-line-arguments.h | 3 +++ +> notmuch-show.c | 10 ++++++++-- +> 3 files changed, 38 insertions(+), 4 deletions(-) +> +> -- +> 1.7.9.1 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch