blob: b29263ddf7444fa1bb781a1b32ee314713798d32 [file] [log] [blame]
Cedric Beust2cc20eb2010-07-12 22:45:52 -07001JCommander
2==========
3
Simon Legner2844c792016-10-05 14:54:13 +02004This is an annotation based parameter parsing framework for Java 8.
Cedric Beust2cc20eb2010-07-12 22:45:52 -07005
Cedric Beust01b687e2010-07-12 22:52:28 -07006Here is a quick example:
7
Joe Littlejohn87678672012-07-14 01:39:19 +02008```java
9public class JCommanderTest {
10 @Parameter
11 public List<String> parameters = Lists.newArrayList();
12
13 @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity")
14 public Integer verbose = 1;
15
16 @Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
17 public String groups;
18
19 @Parameter(names = "-debug", description = "Debug mode")
20 public boolean debug = false;
John Yanic55dc012012-10-25 12:33:30 +030021
22 @DynamicParameter(names = "-D", description = "Dynamic parameters go here")
23 public Map<String, String> dynamicParams = new HashMap<String, String>();
24
Joe Littlejohn87678672012-07-14 01:39:19 +020025}
26```
Cedric Beust01b687e2010-07-12 22:52:28 -070027
28and how you use it:
29
Joe Littlejohn87678672012-07-14 01:39:19 +020030```java
John Yanif50612c2012-10-25 12:52:08 +030031JCommanderTest jct = new JCommanderTest();
John Yanic55dc012012-10-25 12:33:30 +030032String[] argv = { "-log", "2", "-groups", "unit1,unit2,unit3",
John Yanif50612c2012-10-25 12:52:08 +030033 "-debug", "-Doption=value", "a", "b", "c" };
Joe Littlejohn87678672012-07-14 01:39:19 +020034new JCommander(jct, argv);
Cedric Beust01b687e2010-07-12 22:52:28 -070035
John Yanic55dc012012-10-25 12:33:30 +030036Assert.assertEquals(2, jct.verbose.intValue());
John Yanic55dc012012-10-25 12:33:30 +030037Assert.assertEquals("unit1,unit2,unit3", jct.groups);
John Yani459da852012-10-25 12:43:46 +030038Assert.assertEquals(true, jct.debug);
John Yanif50612c2012-10-25 12:52:08 +030039Assert.assertEquals("value", jct.dynamicParams.get("option"));
John Yanic55dc012012-10-25 12:33:30 +030040Assert.assertEquals(Arrays.asList("a", "b", "c"), jct.parameters);
Joe Littlejohn87678672012-07-14 01:39:19 +020041```
Cedric Beust01b687e2010-07-12 22:52:28 -070042
Cedric Beust6b0be062015-11-05 21:09:06 -080043The full doc is available at [http://jcommander.org](http://jcommander.org).
Cedric Beust6db5bf42016-10-04 10:16:18 -070044
45## Building JCommander
46
47```
48./kobaltw assemble
49```
50