groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "KARR, DAVID" <dk0...@att.com>
Subject RE: Example of CliBuilder with "optionalArg: true"?
Date Tue, 02 Feb 2016 19:56:46 GMT
> -----Original Message-----
> From: David M. Karr [mailto:davidmichaelkarr@gmail.com]
> Sent: Tuesday, February 02, 2016 11:42 AM
> To: users@groovy.apache.org
> Subject: Example of CliBuilder with "optionalArg: true"?
> 
> Because someone asked me a question about it, I was looking at
> CliBuilder, for a scenario where "optionalArg" is true, and to get
> the
> value of the option, or detect that it's not present.  I've looked
> at
> the groovydoc, and CliBuilderTest, but it's not clear to me how
> this works.

Adding to this from my alter ego. :)

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]
-------------

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.
Mime
View raw message