Reputation: 36834
(See also https://github.com/remkop/picocli/issues/488)
I have an application that uses a Map
field for an option:
@Option(names = "-P")
Map<String, String> properties;
so users can specify values like:
-Pmyprop=myvalue
Picocli has an option to switch off clustered short options with CommandLine.setPosixClusteredShortOptionsAllowed(false)
.
However, in that configuration, options are no longer recognized when the option value is attached to the option name. The above example -Pmyprop=myvalue
fails with an exception:
picocli.CommandLine$UnmatchedArgumentException: Unknown option: -Pmyprop=myvalue
When I separate the option name -P
and the option value (the key-value pair) with a space, the value is parsed correctly:
-P myprop=myvalue // this works
Is this the expected behaviour? IMO, map options are different from other options, and it would be useful to have the support for the former even when clustered short options are not allowed.
Upvotes: 0
Views: 488
Reputation: 36834
Yes, in picocli 3.6 and earlier this is the expected behaviour.
POSIX allows an option parameter value attached to the last option in a cluster (tar -xvfSomeFile.tar
), while in a GNU-style CLI the option name must be either separated by a space or attached to the option parameter with a =
separator char (--file SomeFile
or --file=SomeFile
).
It seemed natural to me that switching off clustered options would also switch off attached parameter values. If there is interest picocli can be enhanced with a new parser configuration switch.
Upvotes: 0