在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:cbeust/jcommander开源软件地址:https://github.com/cbeust/jcommander开源编程语言:Java 96.9%开源软件介绍:JCommanderThis is an annotation based parameter parsing framework for Java 8. Here is a quick example: public class JCommanderTest {
@Parameter
public List<String> 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<String, String> dynamicParams = new HashMap<String, String>();
} and how you use it: 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. Building JCommander
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论