Command line parsing framework for Java
Java Other
Latest commit 3f95e02 Sep 26, 2016 @cbeust committed on GitHub Merge pull request #294 from simon04/dead-code
Delete commented-out code
Permalink
Failed to load latest commit information.
doc Allow to specify the @file charset Sep 12, 2016
gradle Gradle 2.3. Jul 9, 2015
kobalt Update Kobalt Sep 26, 2016
src Delete commented-out code Sep 26, 2016
.gitignore .gitignore. Feb 28, 2016
.travis.yml JDK 8 Jun 22, 2016
CHANGELOG.md Update CHANGELOG Sep 26, 2016
README.markdown Fix link Nov 6, 2015
build-with-maven Fix build script. Apr 18, 2015
build.gradle TestNG 6.9.4. Aug 24, 2015
gradlew +x flag for gradlew May 2, 2015
kobaltw Update Kobalt Sep 26, 2016
license.txt Updated license Jan 13, 2012
misc.xml IDEA file. Sep 26, 2016
notice.md Updated the pom Aug 6, 2010
pom.xml Enable Java 7 build Jan 21, 2016
release Changed profile name to 'sign' Sep 6, 2010
upload 1.27 Jul 5, 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://jcommander.org.