jcommander

Command line parsing library for Java

License

License

Categories

Categories

JCommander User Interface CLI
GroupId

GroupId

bayern.steinbrecher
ArtifactId

ArtifactId

jcommander
Last Version

Last Version

1.80
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

jcommander
Command line parsing library for Java
Project URL

Project URL

https://jcommander.org
Source Code Management

Source Code Management

https://github.com/cbeust/jcommander

Download jcommander

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

JCommander

This is an annotation based parameter parsing framework for Java 8.

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" };
JCommander.newBuilder()
  .addObject(jct)
  .build()
  .parse(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 https://jcommander.org.

Building JCommander

./gradlew assemble

Versions

Version
1.80