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. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:[email protected] 41 Buckmaster Road m: +44 7770 465 077 xmpp: [email protected] London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc
Description: This is a digitally signed message part
