Skip to content

Parser config: validate arity after split #313

@remkop

Description

@remkop

Needed to implement #258 in a way that is backwards compatible with commons-cli. Commons-cli models Java properties like this:

Option property  = OptionBuilder.withArgName( "property=value" )
                                .hasArgs(2)
                                .withValueSeparator('=')
                                .withDescription( "use value for given property" )
                                .create( "D" );

Arity in picocli is used to indicate the number of "raw" command line arguments consumed by an option. "Raw" arguments means the arguments as they are specified on the command line, before they are split into parts.

In the picocli model, an argument to a Map option like -Dkey=value would be counted as a single argument. Similarly, list-like options with a separator, e.g. -x a,b,c (where split=",") would count the a,b,c argument as a single command line argument.

Commons-cli throws an exception if the result of splitting the argument into components results in more values than was specified in hasArgs. Picocli should offer a similar parsing mode, so that after setting CommandLine.validateArityAfterSplit(true), a value like -Dkey=value=wrong would result in a MaxValuesExceededException.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions