blob: 048bc3991bdc3b2ae3a7baf04577aab41ce3396f [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
31CommanderTest jct = new JCommanderTest();
John Yanic55dc012012-10-25 12:33:30 +030032String[] argv = { "-log", "2", "-groups", "unit1,unit2,unit3",
33 "-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());
37
38Assert.assertEquals("unit1,unit2,unit3", jct.groups);
39
40Map<String, String> params = new HashMap<String, String>();
41params.put("option", "value");
42Assert.assertEquals(params, jct.params);
43
44Assert.assertEquals(Arrays.asList("a", "b", "c"), jct.parameters);
Joe Littlejohn87678672012-07-14 01:39:19 +020045```
Cedric Beust01b687e2010-07-12 22:52:28 -070046
Cedric Beustbb96cc82010-07-13 07:12:41 -070047The full doc is available at http://beust.com/jcommander