Skip to content
This repository

Command line parsing framework for Java

Merge pull request #188 from madrob/master

Added another test for using '--'
latest commit 649895bc27
Cedric Beust authored
Octocat-spinner-32 doc Typo error in documentation January 17, 2014
Octocat-spinner-32 src Broke parsing of -- April 10, 2014
Octocat-spinner-32 .gitignore .gitignore August 07, 2012
Octocat-spinner-32 CHANGELOG Wrong file. November 11, 2012
Octocat-spinner-32 README.markdown Update README.markdown October 25, 2012
Octocat-spinner-32 build-with-maven Preparing next release. February 22, 2014
Octocat-spinner-32 license.txt Updated license January 13, 2012
Octocat-spinner-32 notice.md Updated the pom August 05, 2010
Octocat-spinner-32 pom.xml [maven-release-plugin] prepare for next development iteration February 22, 2014
Octocat-spinner-32 release Changed profile name to 'sign' September 06, 2010
Octocat-spinner-32 upload 1.27 July 05, 2012
README.markdown

JCommander

This is an annotation based parameter parsing framework for Java.

Here is a quick example:

public class JCommanderTest {
    @Parameter
    public List<String> parameters = Lists.newArrayList();

    @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
    public Integer verbose = 1;

    @Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
    public String groups;

    @Parameter(names = "-debug", description = "Debug mode")
    public boolean debug = false;

    @DynamicParameter(names = "-D", description = "Dynamic parameters go here")
    public Map<String, String> dynamicParams = new HashMap<String, String>();

}

and how you use it:

JCommanderTest jct = new JCommanderTest();
String[] argv = { "-log", "2", "-groups", "unit1,unit2,unit3",
                    "-debug", "-Doption=value", "a", "b", "c" };
new JCommander(jct, argv);

Assert.assertEquals(2, jct.verbose.intValue());
Assert.assertEquals("unit1,unit2,unit3", jct.groups);
Assert.assertEquals(true, jct.debug);
Assert.assertEquals("value", jct.dynamicParams.get("option"));
Assert.assertEquals(Arrays.asList("a", "b", "c"), jct.parameters);

The full doc is available at http://beust.com/jcommander

Something went wrong with that request. Please try again.