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
Octocat-spinner-32 src Broke parsing of --
Octocat-spinner-32 .gitignore .gitignore
Octocat-spinner-32 CHANGELOG Wrong file.
Octocat-spinner-32 README.markdown Update README.markdown
Octocat-spinner-32 build-with-maven Preparing next release.
Octocat-spinner-32 license.txt Updated license
Octocat-spinner-32 Updated the pom
Octocat-spinner-32 pom.xml [maven-release-plugin] prepare for next development iteration
Octocat-spinner-32 release Changed profile name to 'sign'
Octocat-spinner-32 upload 1.27


This is an annotation based parameter parsing framework for Java.

Here is a quick example:

public class JCommanderTest {
    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

Something went wrong with that request. Please try again.