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 196BB184BC for ; Mon, 8 Feb 2016 17:12:07 +0000 (UTC) Received: (qmail 67674 invoked by uid 500); 8 Feb 2016 17:12:06 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 67646 invoked by uid 500); 8 Feb 2016 17:12:06 -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 67636 invoked by uid 99); 8 Feb 2016 17:12:06 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Feb 2016 17:12:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 5D5F6180473 for ; Mon, 8 Feb 2016 17:12:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.571 X-Spam-Level: X-Spam-Status: No, score=0.571 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.429] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id pYrA1F79QFSf for ; Mon, 8 Feb 2016 17:12:05 +0000 (UTC) Received: from dimen.winder.org.uk (dimen.winder.org.uk [87.127.116.10]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id 9229E31AD0 for ; Mon, 8 Feb 2016 17:12:04 +0000 (UTC) Received: from anglides.winder.org.uk (anglides.winder.org.uk [192.168.1.8]) by dimen.winder.org.uk (Postfix) with ESMTPSA id 515EA60028A; Mon, 8 Feb 2016 17:11:58 +0000 (GMT) Message-ID: <1454951518.2264.64.camel@winder.org.uk> Subject: Re: Example of CliBuilder with "optionalArg: true"? From: Russel Winder To: users@groovy.apache.org Date: Mon, 08 Feb 2016 17:11:58 +0000 In-Reply-To: References: <56B106A3.70803@gmail.com> Content-Type: multipart/signed; micalg="pgp-sha1"; protocol="application/pgp-signature"; boundary="=-ME1JSbtMiftynv6mWAvz" X-Mailer: Evolution 3.18.3-1 Mime-Version: 1.0 --=-ME1JSbtMiftynv6mWAvz Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 2016-02-02 at 19:56 +0000, KARR, DAVID wrote: > >=20 [=E2=80=A6] > With a=C2=A0=C2=A0simple script like this: > ---------------- > def cli =3D new CliBuilder() > cli.with {=C2=A0 > =C2=A0 f(args: 1, optionalArg: true, "set a value") > } > def options =3D cli.parse(args) > def fval =3D options.f > println "fval[" + fval + "] class[" + fval.getClass().getName() + "]" > def fvalue =3D options.fs > println "fvalue[" + fvalue + "]" > --- >=20 > If I run this with "-f abc", I get: > -------------- > fval[abc] class[java.lang.String] > fvalue[[abc]] > ---------------- >=20 > 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. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder --=-ME1JSbtMiftynv6mWAvz Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEABECAAYFAla4zF4ACgkQ+ooS3F10Be8wIgCfT0RpR6FiZPD8mN51g9Hf/ABN 4MQAn1OMcuVajsKtekLrwUUKupjRtEZR =Sy7g -----END PGP SIGNATURE----- --=-ME1JSbtMiftynv6mWAvz--