Thank you for clarifying the use case: there is an option with an optional parameter, and this introduces ambiguity.
I like your proposed solution to try to disambiguate the input with a '=' separator;
it is intuitive that `A` is the option parameter in a command like `jbang edit --open=A B`, where `jbang edit --open A B` is more ambiguous.
The drawback is that users need to know this.
A similar solution (that already works with all versions of picocli) is to disambiguate with the `--`
end-of-options delimiter.
`jbang edit --open -- A B` # both A and B are positional parameters
`jbang edit --open A -- B` # A is a parameter for the open option and B is a positional parameter
This has the same drawback that users need to know this.
Arguably the `--` end-of-options delimiter is less well-known, although it can be shown in the usage help with `@Command(showEndOfOptionsDelimiterInUsageHelp=true)`.
Still, this is something to consider for commands that define both an option with an optional parameter and a positional parameter.
Ultimately, this is a limitation of the picocli parser: if a command has an option with an optional parameter (like --live[=editor]), then the picocli parser will currently greedily assign the value that follows the option to this option. This is regardless of whether the command also defines a positional parameter and the last argument could also have been interpreted as that positional parameter. This is especially painful if the positional parameter is mandatory (see
https://github.com/remkop/picocli/issues/981).
it essentially requires the parser to detect ambiguity (all options or positional parameters whose arity is a range instead of a fixed number),
and build up multiple parse results: one for each possible interpretation of the input.
If we succeed in that, we need to decide what to do in cases where
* all interpretations failed (what error message to produce)
* multiple interpretations succeeded (which one to choose)
Your idea to disambiguate with '=' will not solve the full range of ambiguity problems, but it may be easier to implement than a backtracking parser.
Currently I can think of two mechanisms to do this:
1. introduce a new `@Option(assignFallbackWhenSeparatorMissing = true|false)` attribute.
For options with an optional parameter, this attribute would tell the parser to use the '=' separator to disambiguate the input.
The value following the option is _only_ considered to be the option parameter if the value is attached to the option with the '=' separator.
2. introduce a new `IParameterConsumer2` interface, that takes an additional `LookBehind { SEPARATE, ATTACHED, ATTACHED_WITH_SEPARATOR}` enum parameter to the `consumeParameters` method.
We would also need an additional `@Option(parameterConsumer2 = <class>)` attribute.
Applications can then use this to build custom disambiguation logic.
3. Somehow make this information (of whether a separator was specified or not) available to implementors of the existing `IParameterConsumer` interface.
Perhaps by adding some method on `ArgSpec`, `CommandSpec` or any object reachable from these objects.
Of by setting a static ThreadLocal. :-)
There may be other approaches, please let me know your thoughts.
Remko.