我尝试使用 apache commons cli ,我的用例是带有一些选项的可变数量的参数。
Say
-p str1 str2;
有可能
-p str1 str2 str3 .. strn
另一个是
-m str1
-h
with
cmdline.getOptionValues("p");
它仅获取最后一个字符串。如何获取特定选项的所有值?
Edit:
if(cmdline.hasOption("p")){
String[] argsList = cmdline.getOptionValues(p);
String strLine = Arrays.toString(argsList);
argsList = strLine.split(",");
}
我做对了吗?字符串是否由我想要的数据或意外的空格或其他内容组成?
Use hasArgs()
值分隔符设置为逗号,因此选项变为
-p str1,str2,str3,...,strn
这是 CLI 中处理多值选项的方式
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)