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]