Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 749D418B39 for ; Mon, 8 Feb 2016 22:33:42 +0000 (UTC) Received: (qmail 13214 invoked by uid 500); 8 Feb 2016 22:33:42 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 13187 invoked by uid 500); 8 Feb 2016 22:33:42 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 13177 invoked by uid 99); 8 Feb 2016 22:33:42 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Feb 2016 22:33:42 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id CC66DC00EC for ; Mon, 8 Feb 2016 22:33:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.821 X-Spam-Level: X-Spam-Status: No, score=-0.821 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 8W2OzwjTCO4H for ; Mon, 8 Feb 2016 22:33:41 +0000 (UTC) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTPS id 02D482050D for ; Mon, 8 Feb 2016 22:33:41 +0000 (UTC) Received: by mail-pa0-f52.google.com with SMTP id yy13so80286522pab.3 for ; Mon, 08 Feb 2016 14:33:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=1DyxLQzOSeOcqimERln/KJazkKehTTfkV+NP6ORXM7o=; b=TrRa6mxInZV6aCdTQJJfNWt3x0+E6IUbjauMPQp159iC27ujRHbmP+COpGlEXpTCjM aFMrRdlqw2XcSBAXUJdI4Yi1wWZ/CQNNEHpxyAyz/4AtgmOca2ctfuqsSNWB0ryrfPdJ nDPoILWlvKJq9BzRBPhBYiF5xrb4hd5bIB59yDlBuHJiRw8p/cZAbiFwQZsKuxwKKLXx yXXP8BYKajd1BWy+cpKZNFRVOhQh/HoKK7G/LCDkoKrVyO+RXc0fV0zELcONads94lCK i/YUZzyMoNWpreoVHIEdOS7f8biEGBydNP8snJnoryQnsBsd16QT7kohcS/AWuRdA9Oy MI7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=1DyxLQzOSeOcqimERln/KJazkKehTTfkV+NP6ORXM7o=; b=HoEN99IdoLR3BC92zqHru6PtIRDatjuC3IsOQx9Q7L5P58kDcdBbsMXAQtvmArkFAn W9GP6jhvI37drFoyYm6RaR6b15Z5fz3ORdGcZreg3V/VvSUQ+96CXstRsJVSgXW6Jz/X pcYGgQRLxGgMPOvpkeTlQV8IAuTKjBw17m91fVx+DKAQMzoGDVeWHJaQzCeFMklMQC3N M7T+u1Ll2WtL2btPK4eeJjVVwTpADri27+0NNEwcYYSI6If6yARiYId33QULi51R2ZR6 L2NCMsG9rW8ghMepAWWz7udyi5joXJxHpbrR3xEvNmneO8sJNGu6AEDqhF1niSNqChoh j7ug== X-Gm-Message-State: AG10YOQnLzrS5DJURVQAipUTNkPrNxTALsu4l/NPED0dYOJrkLR0VWaVfNKc1QV0+aSqOw== X-Received: by 10.66.120.200 with SMTP id le8mr45944733pab.61.1454970820737; Mon, 08 Feb 2016 14:33:40 -0800 (PST) Received: from localhost.localdomain (mobile-166-176-186-123.mycingular.net. [166.176.186.123]) by smtp.gmail.com with ESMTPSA id o184sm45634916pfo.36.2016.02.08.14.33.39 for (version=TLSv1/SSLv3 cipher=OTHER); Mon, 08 Feb 2016 14:33:40 -0800 (PST) Subject: Re: Example of CliBuilder with "optionalArg: true"? To: users@groovy.apache.org References: <56B106A3.70803@gmail.com> <1454951518.2264.64.camel@winder.org.uk> From: "David M. Karr" Message-ID: <56B917C3.8010905@gmail.com> Date: Mon, 8 Feb 2016 14:33:39 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <1454951518.2264.64.camel@winder.org.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 02/08/2016 09:11 AM, Russel Winder wrote: > On Tue, 2016-02-02 at 19:56 +0000, KARR, DAVID wrote: > […] >> With a simple script like this: >> ---------------- >> def cli = new CliBuilder() >> cli.with { >> f(args: 1, optionalArg: true, "set a value") >> } >> def options = cli.parse(args) >> def fval = options.f >> println "fval[" + fval + "] class[" + fval.getClass().getName() + "]" >> def fvalue = options.fs >> println "fvalue[" + fvalue + "]" >> --- >> >> If I run this with "-f abc", I get: >> -------------- >> fval[abc] class[java.lang.String] >> fvalue[[abc]] >> ---------------- >> >> But if I run it with "-f", I get: >> ------------ >> fval[true] class[java.lang.Boolean] >> fvalue[true] >> ------------- > And if you run without -f on the command line you get: > > fval[false] class[java.lang.Boolean] > fvalue[false] > > So I think we are looking at this being a feature of options with the > optionalArg property set. Without it not having an argument to -f > fails. > >> I suppose I could hack something with this information, but I would >> think there would be something more explicit to tell me whether an >> argument was supplied for the option. > Thinking about this, I would say it is right that this behaviour is a > feature, and that it is what the code has asked for: an option that can > deliver presence or a value. When the is a value deliver it, otherwise > deliver a Boolean stating whether the flag was present. > > Clearly managing this type of option is non-trivial, but I think this > is not a bug. > Thanks for doing that analysis. Whether it's a bug is debatable, but I think it's clear that overloading behaviors often create confusion. A friendlier interface would separate the notion of "presence of the option" from "value of the argument". However, doing that might make all references to options more verbose, which is certainly not ideal. I suppose an improvement could be made by just putting a little pseudocode algorithm in the doc that shows how you would either retrieve a value if it's present, or determine it's not there, I suppose by checking the class of the value returned from "options.