From my point of view, the options have the same basic type: the list of inputs to operate on. In one case it is "all inputs" to the overall program, in the other it is a sublist of the inputs. I could provide a second option to specify "all inputs", but I'd rather just have one option for the very similar functionality.
The way I would use this in JCommander is to have the field have a custom type with a custom string converter, and allow passing null to the string converter when an option argument is omitted:
public class ProgramOptions
{
@Parameter (names="--operation", converter=OperationInputsConverter.class)
private OperationInputs operationInputs;
...
}
public class OperationInputsConverter implements IStringConverter<OperationInputs>
{
public OperationInputs convert(String value)
{
if (value == null)
{
// optional argument was not supplied.
}
}
}
Paolo's
solution is better. Like values provided by
IDefaultProvider, the optional value could be passed to the string
converter to construct the value for the default argument.