Cedric Beust | 2cc20eb | 2010-07-12 22:45:52 -0700 | [diff] [blame] | 1 | JCommander |
| 2 | ========== |
| 3 | |
| 4 | This is an annotation based parameter parsing framework for Java. |
| 5 | |
Cedric Beust | 01b687e | 2010-07-12 22:52:28 -0700 | [diff] [blame] | 6 | Here is a quick example: |
| 7 | |
| 8 | public class JCommanderTest { |
| 9 | @Parameter |
| 10 | public List<String> parameters = Lists.newArrayList(); |
| 11 | |
| 12 | @Parameter(names = { "-log", "-verbose" }, description = "Level of verbosity") |
| 13 | public Integer verbose = 1; |
| 14 | |
| 15 | @Parameter(names = "-groups", description = "Comma-separated list of group names to be run") |
| 16 | public String groups; |
| 17 | |
| 18 | @Parameter(names = "-debug", description = "Debug mode") |
| 19 | public boolean debug = false; |
| 20 | } |
| 21 | |
| 22 | and how you use it: |
| 23 | |
| 24 | JCommanderTest jct = new JCommanderTest(); |
| 25 | String[] argv = { "-log", "2", "-groups", "unit", "a", "b", "c" }; |
| 26 | new JCommander(jct, argv); |
| 27 | |
| 28 | Assert.assertEquals(jct.verbose.intValue(), 2); |
Cedric Beust | 01b687e | 2010-07-12 22:52:28 -0700 | [diff] [blame] | 29 | |
Cedric Beust | bb96cc8 | 2010-07-13 07:12:41 -0700 | [diff] [blame^] | 30 | The full doc is available at http://beust.com/jcommander |