jcommander icon indicating copy to clipboard operation
jcommander copied to clipboard

Support no value on dynamic parameters

Open henryju opened this issue 12 years ago • 4 comments

I would like to support something like: java Main -Da=b -De -Dc=d Here the second argument doesn't provide a value. This is a common practice with Maven plugins (for example -DskipTests).

Would it be possible to enhance @DynamicParameter to support this syntax. I would expect that the Map will contains an entry with key="e" and value=null.

henryju avatar Jan 03 '13 15:01 henryju

+1

j-coll avatar Mar 20 '15 15:03 j-coll

@cbeust still an issue

public void dynamic() {
        class Args {
            @DynamicParameter(names = "-D", description = "Dynamic parameters go here")
            private Map<String, String> params = new HashMap<>();
        }

        JCommander jc = new JCommander();
        Args args = new Args();
        jc.addObject(args);

        jc.parse("-Da=b","-De","-Dc=d");

        Assert.assertEquals(3, args.params.size());
    }

Worth implementing?

jeremysolarz avatar Mar 05 '17 19:03 jeremysolarz

Yes. that's a reasonable request.

cbeust avatar Mar 06 '17 02:03 cbeust

+1 for this. Any idea on when this will be available?

pubudu91 avatar Aug 21 '17 06:08 pubudu91