def cli = new CliBuilder(
usage: 'testFile -n yourName',
header: '\nAvailable options (use -h for help):\n',
footer: '\nInformation provided via above options is used to generate
printed string.\n')
cli.with{
h(longOpt: 'help', 'Help - Usage Information')
n(longOpt: 'name', 'Name to say hello to', type: String, required: true)
}
def opt = cli.parse(args)
if (opt.h) cli.usage()
if (opt.n) {
println "Hello ${opt.n}"
}
Why I have got this error massage without to specify any parameters:
Exception in thread "main" java.lang.NullPointerException: Cannot get
property 'h' on null object
at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
at
org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:156)
at
org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:235)
at testFile.run(testFile.groovy:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1058)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
at
org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:793)
at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:776)
at
org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:394)
at org.codehaus.groovy.runtime.InvokerHelper$runScript.call(Unknown Source)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
at testFile.main(testFile.groovy)
How is possible to get the help without the above error?
Thank you in advance.
--
View this message in context: http://groovy.329449.n5.nabble.com/CliBuilder-problem-tp4340202p4340202.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Cheers,
Dinko
--
View this message in context: http://groovy.329449.n5.nabble.com/CliBuilder-problem-tp4340202p4340850.html