Skip to content

fallbackValue is not applied for vararg multi-value options (was: Support fallbackValue with arity="0..*") #1904

@sewe

Description

@sewe

Please support fallbackValue with "zero-based" arities other than 0..1, in particular with 0..*.

To see why this might be useful, consider the following @Option definition:

enum DebugFacility { FOO, BAR, BAZ, ALL }

@Option(
    names = { "--debug" },
    paramLabel = "FACILITY", //
    split = ",",
    arity = "0..*", //
    fallbackValue = "ALL", //
    description = "The facilities for which to log debug information (one or more of ${COMPLETION-CANDIDATES}). "
        + "If none are given, debug information will be logged for ${FALLBACK-VALUE} categories.")
public void setDebugFacilities(Collection<DebugFacility> facilities) { ... }

This should support the following scenarios

--debug FOO               -> FOO
--debug FOO --debug BAR   -> FOO, BAR
--debug FOO,BAR           -> FOO, BAR
--debug all               -> ALL (i.e., FOO, BAR, BAZ)
--debug                   -> ALL (i.e., FOO, BAR, BAZ)

The last one unfortunately doesn't work, as the fallbackValue does not get passed to setDebugFacilities; it merely gets an empty facilities Collection.

And we can't insert ALL programmatically in setDebugFacilities, either. To see why, consider the following scenario:

--debug FOO --debug       -> ALL (i.e., FOO, BAR, BAZ)

Here, the parameterless --debug simply results in another call of setDebugFacilities with FOO as single parameter. In other words, one cannot detect the parameterless case

Maybe there is a workaround that I am unable to see, but IMHO fallbackValue support for any "zero-based" arity might be the most idiomatic solution. WDYT?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions