Skip to content

arity should support with list parameter to support multiple occurence of the param #606

@atulgpt

Description

@atulgpt

Following TC should pass

@Test
public void arity() {
    class Parameters {
        @Parameter(names = {"--mv"}, arity = 2)
        private List<MvParameters> mvParameters;
    }

    Parameters args = new Parameters();
    JCommander.newBuilder()
            .addObject(args)
            .args(new String[]{"--mv", "from1", "to1", "--mv", "from2", "to2"})
            .build();

    Assert.assertNotNull(args.mvParameters);
    Assert.assertEquals(args.mvParameters.size(), 2);
    Assert.assertEquals(args.mvParameters.getFirst().from, "from1");
    Assert.assertEquals(args.mvParameters.getFirst().to, "to1");
    Assert.assertEquals(args.mvParameters.getLast().from, "from2");
    Assert.assertEquals(args.mvParameters.getLast().to, "to2");
}

I want to run the command like below

./my_cmd --mv to1 from1 --mv to2 from2

I also saw a mention in the doc Also, note that only List<String> is allowed for parameters that define an arity. You will have to convert these values yourself if the parameters you need are of type Integer or other (this limitation is due to Java’s erasure). in 10.1. Fixed arities at doc. If same limitation applies here then this issue can be closed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions