Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cbeust/jcommander
Command line parsing framework for Java
https://github.com/cbeust/jcommander
Last synced: about 2 months ago
JSON representation
Command line parsing framework for Java
- Host: GitHub
- URL: https://github.com/cbeust/jcommander
- Owner: cbeust
- License: apache-2.0
- Created: 2010-07-13T05:40:31.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2024-07-06T15:59:53.000Z (6 months ago)
- Last Synced: 2024-07-06T17:01:56.906Z (6 months ago)
- Language: Java
- Homepage:
- Size: 31.7 MB
- Stars: 1,934
- Watchers: 60
- Forks: 328
- Open Issues: 106
-
Metadata Files:
- Readme: README.markdown
- Changelog: CHANGELOG.md
- License: license.txt
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-cli-frameworks - Jcommander
README
JCommander
==========This is an annotation based parameter parsing framework for Java 8 (JCommander 1.x), 11 (JCommander 2.x) and 17 (JCommander 3.x).
Here is a quick example:
```java
public class JCommanderTest {
@Parameter
public List 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 dynamicParams = new HashMap();}
```and how you use it:
```java
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](https://jcommander.org).
## Building JCommander
```
./gradlew assemble
```