You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Maarten Mulders <mt...@apache.org> on 2021/11/05 13:59:43 UTC

[cli] Parsing arguments with an equals sign

Hi all,

In Apache Maven, we're working to upgrade Commons CLI 1.4 to 1.5.0 [1]. 
Until now, we were using the (deprecated) GnuParser from Commons CLI, 
and we decided that we want to move to DefaultParser. The transition has 
been pretty smooth but there's one use case we're struggling with.

As you may know, Maven allows to set properties using -D. A popular 
example is -DskipTests... Even though -D mimics the JVM switch with the 
same name, the primary purpose of this switch is to set a Maven 
property. This switch also has a longer version, --define. It is often 
used like this: -Dmykey=myvalue, and consequently, it could be used as 
--define mykey=myvalue.

Unfortunately, the latter no longer works in Commons CLI 1.5.0 with the 
DefaultParser. I've been debugging the Commons CLI code and it seems to 
look for an option called "define mykey" rather than "define". As a 
result, parsing the command line args breaks because we never declared 
an option "define mykey".

What we do declare is this:

     Option.builder("D")
         .longOpt("define")
         .hasArgs()
         .valueSeparator('=')
         .build()


Should it possible to parse a command line like I mentioned above: mvn 
--define mykey=myvalue? If so, how should we be doing that?


Thanks,


Maarten


[1] https://github.com/apache/maven/pull/605

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [cli] Parsing arguments with an equals sign

Posted by Gary Gregory <ga...@gmail.com>.
Hi Maarten,

Reading the examples on
https://commons.apache.org/proper/commons-cli/usage.html, I can see why it
is behaving like this. You might have to not specify the value separator
and split on the '=' in the resulting value yourself, just a guess though.

Gary

On Fri, Nov 5, 2021, 10:15 Maarten Mulders <mt...@apache.org> wrote:

> Hi all,
>
> In Apache Maven, we're working to upgrade Commons CLI 1.4 to 1.5.0 [1].
> Until now, we were using the (deprecated) GnuParser from Commons CLI,
> and we decided that we want to move to DefaultParser. The transition has
> been pretty smooth but there's one use case we're struggling with.
>
> As you may know, Maven allows to set properties using -D. A popular
> example is -DskipTests... Even though -D mimics the JVM switch with the
> same name, the primary purpose of this switch is to set a Maven
> property. This switch also has a longer version, --define. It is often
> used like this: -Dmykey=myvalue, and consequently, it could be used as
> --define mykey=myvalue.
>
> Unfortunately, the latter no longer works in Commons CLI 1.5.0 with the
> DefaultParser. I've been debugging the Commons CLI code and it seems to
> look for an option called "define mykey" rather than "define". As a
> result, parsing the command line args breaks because we never declared
> an option "define mykey".
>
> What we do declare is this:
>
>      Option.builder("D")
>          .longOpt("define")
>          .hasArgs()
>          .valueSeparator('=')
>          .build()
>
>
> Should it possible to parse a command line like I mentioned above: mvn
> --define mykey=myvalue? If so, how should we be doing that?
>
>
> Thanks,
>
>
> Maarten
>
>
> [1] https://github.com/apache/maven/pull/605
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>