airlift / airline

Java annotation-based framework for parsing Git like command line structures

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conflicting arguments, although they don't conflict

tinwelint opened this issue · comments

I have a command with two arguments:

@Arguments( title = "recordType", description = "Record type", required = true )
public String recordType;

@Arguments( title = "id", description = "Record id", required = true )
public long id;

when building a CLI for that command I get exception:

java.lang.IllegalArgumentException: Conflicting arguments definitions: ArgumentsMetadata{title='recordType', description='Record type', usage='', required=true, accessors=[DumpPropertyChain.recordType]}, ArgumentsMetadata{title='id', description='Record id', usage='', required=true, accessors=[DumpPropertyChain.id]}
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:145)
    at io.airlift.airline.model.ArgumentsMetadata.<init>(ArgumentsMetadata.java:48)
    at io.airlift.airline.model.MetadataLoader$InjectionMetadata.compact(MetadataLoader.java:257)
    at io.airlift.airline.model.MetadataLoader$InjectionMetadata.access$600(MetadataLoader.java:242)
    at io.airlift.airline.model.MetadataLoader.loadInjectionMetadata(MetadataLoader.java:112)
    at io.airlift.airline.model.MetadataLoader.loadCommand(MetadataLoader.java:86)
    at io.airlift.airline.model.MetadataLoader$1.apply(MetadataLoader.java:70)
    at io.airlift.airline.model.MetadataLoader$1.apply(MetadataLoader.java:67)
    at com.google.common.collect.Iterators$8.transform(Iterators.java:799)
    at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
    at com.google.common.collect.ImmutableCollection$Builder.addAll(ImmutableCollection.java:301)
    at com.google.common.collect.ImmutableList$Builder.addAll(ImmutableList.java:691)
    at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:275)
    at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:226)
    at io.airlift.airline.model.MetadataLoader.loadCommands(MetadataLoader.java:66)
    at io.airlift.airline.Cli.<init>(Cli.java:77)
    at io.airlift.airline.Cli.<init>(Cli.java:40)
    at io.airlift.airline.Cli$CliBuilder.build(Cli.java:246)
    ...

The two arguments doesn't conflict. Instead this looks to be an issue at https://github.com/airlift/airline/blob/master/src/main/java/io/airlift/airline/model/ArgumentsMetadata.java#L48 where that condition looks to be negated... i.e. it will always report conflict if there are more than one argument defined.

I think this is because @Arguments is supposed to be used over a List<String> attribute - this way it passes all the arguments to the list and it is left for the developer to make error checks and then use them in his own way.

Refer #6 for more details.