You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by LAURENT Frederic SZSIC13 softeam <fr...@interieur.gouv.fr> on 2003/12/10 17:15:10 UTC
[CLI] UnrecognizedOptionException on simple test
Hello
I am trying to make a simple test working with CLI, but without
success :(
Well, I add an Option (ie "url"), and when I test this command
line
java fooMain -url http://foo.com
an exception is thrown
org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option:
-u
Here some Jython code of what I am doing
>>> options = Options()
>>> OptionBuilder.withArgName("url")
org.apache.commons.cli.OptionBuilder@1795327
>>> OptionBuilder.hasArg()
org.apache.commons.cli.OptionBuilder@1795327
>>> OptionBuilder.withDescription("an url")
org.apache.commons.cli.OptionBuilder@1795327
>>> url = OptionBuilder.create("url")
>>> options.addOption(url)
[ Options: [ short {-url=[ option: url :: an url ]} ] [ long {} ]
>>> test="-url http://foo.com"
>>> parser=PosixParser()
>>> line = parser.parse(options,[String(test)])
Traceback (innermost last):
File "<console>", line 1, in ?
org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -u
at org.apache.commons.cli.Parser.processOption(Parser.java:253)
at org.apache.commons.cli.Parser.parse(Parser.java:170)
at org.apache.commons.cli.Parser.parse(Parser.java:114)
...
then If I remove the '-', no exception is thrown but the result is
null (None in Jython)
>>>>>> test="url http://foo.com"
>>>>>> line = parser.parse(options,[String(test)])
>>>>>> print line.getOptionValue("url")
None
I have downloaded the zip file available on the jakarta website (1.0),
and so I do not get sources from cvs.
any idea ?
thanks
--
XPath free testing software : http://lantern.sourceforge.net
Frédéric Laurent http://www.opikanoba.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [CLI] UnrecognizedOptionException on simple test
Posted by LAURENT Frederic SZSIC13 softeam <fr...@interieur.gouv.fr>.
Martin van den Bemt wrote:
> Tried --url instead of -url? Normally the single dash is for single
> letter parmater names and the double dash for the "readable" name..
> Not a cli developer / user though..
well I've got another wrong result :( (wich seems to be correct)
>>> test="--url http://foo.com"
>>> parser=PosixParser()
>>> line = parser.parse(options,[String(test)])
Traceback (innermost last):
File "<console>", line 1, in ?
org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option:
--url http://foo.com
at org.apache.commons.cli.Parser.processOption(Parser.java:253)
...
According to the documentation [*], if you want a -listener argument you
have to create an option by invoking the OptionBuilder like this
Option listener = OptionBuilder.withArgName( "classname" )
.hasArg()
.withDescription( "add an instance of class as "
+ "a project listener" )
.create( "listener");
[*] http://jakarta.apache.org/commons/cli/usage.html
Fred
--
XPath free testing software : http://lantern.sourceforge.net
Frédéric Laurent http://www.opikanoba.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [CLI] UnrecognizedOptionException on simple test
Posted by Martin van den Bemt <ml...@mvdb.net>.
Tried --url instead of -url? Normally the single dash is for single
letter parmater names and the double dash for the "readable" name..
Not a cli developer / user though..
Mvgr,
Martin
On Wed, 2003-12-10 at 17:15, LAURENT Frederic SZSIC13 softeam wrote:
> Hello
>
> I am trying to make a simple test working with CLI, but without
> success :(
> Well, I add an Option (ie "url"), and when I test this command
> line
>
> java fooMain -url http://foo.com
>
> an exception is thrown
>
> org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option:
> -u
>
> Here some Jython code of what I am doing
>
> >>> options = Options()
> >>> OptionBuilder.withArgName("url")
> org.apache.commons.cli.OptionBuilder@1795327
> >>> OptionBuilder.hasArg()
> org.apache.commons.cli.OptionBuilder@1795327
> >>> OptionBuilder.withDescription("an url")
> org.apache.commons.cli.OptionBuilder@1795327
> >>> url = OptionBuilder.create("url")
> >>> options.addOption(url)
> [ Options: [ short {-url=[ option: url :: an url ]} ] [ long {} ]
>
> >>> test="-url http://foo.com"
> >>> parser=PosixParser()
> >>> line = parser.parse(options,[String(test)])
>
> Traceback (innermost last):
> File "<console>", line 1, in ?
> org.apache.commons.cli.UnrecognizedOptionException: Unrecognized option: -u
> at org.apache.commons.cli.Parser.processOption(Parser.java:253)
> at org.apache.commons.cli.Parser.parse(Parser.java:170)
> at org.apache.commons.cli.Parser.parse(Parser.java:114)
> ...
>
>
> then If I remove the '-', no exception is thrown but the result is
> null (None in Jython)
>
>
> >>>>>> test="url http://foo.com"
> >>>>>> line = parser.parse(options,[String(test)])
> >>>>>> print line.getOptionValue("url")
> None
>
> I have downloaded the zip file available on the jakarta website (1.0),
> and so I do not get sources from cvs.
>
> any idea ?
>
> thanks
--
Martin van den Bemt <ml...@mvdb.net>
mvdb.com
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org