blob: 0aecbf565b6a6cce2111be91b008f97ddf39f2f0 [file] [log] [blame]
Cedric Beust2cc20eb2010-07-12 22:45:52 -07001JCommander
2==========
3
4This is an annotation based parameter parsing framework for Java.
5
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 Beustbb96cc82010-07-13 07:12:41 -070043The full doc is available at http://beust.com/jcommander