Consider the following options scenario:
Option.builder("1").longOpt("one").hasArgs().build()
Option.builder("2").longOpt("two").hasArg().required().build()
with the following args:
String[] args = {"--one","arg1","-2","arg2"}
It should consider -2 as an argument or an option? Because, the option 2 is set
to be required.
Currently, -2 is being treated as an argument
On Monday, November 13th, 2023 at 4:22 AM, Paul King
<[email protected]> wrote:
> I think this question only makes sense if you give the Options spec
> you are using.
>
> Using an Options with both of these:
>
> Option.builder().longOpt('one').numberOfArgs(1).build()
> Option.builder('2').numberOfArgs(1).build()
>
> It treats the "-2" as you are expecting.
>
> Using an Options with both of these:
>
> Option.builder().longOpt('one').numberOfArgs(2).optionalArg(true).build()
> opts.addOption(Option.builder('2').numberOfArgs(1).build()
>
> It gives the behavior you are describing, since indeed the "-2" could
> be an optional argument.
>
> Is there any reason you couldn't use the former?
>
> Cheers, Paul.
>
> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
>
> Virus-free.www.avast.com
> https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail
>
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
>
> On Sun, Nov 12, 2023 at 7:52 PM Sruteesh Kumar
> [email protected] wrote:
>
> > I have a doubt on Apache Commons CLI
> >
> > For DefaultParser, why is a negative number preferably considered as an
> > argument rather than an option
> >
> > Consider the following case, for example:
> > String[] args= {"--one","arg1","-2","arg2"};
> >
> > Here, -2 is considered as an argument to --one, even if there is a required
> > option with key -2
> >
> > Why is it preferably considered as an argument rather than an option?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]