本文整理汇总了Java中org.apache.commons.cli2.CommandLine.getValues方法的典型用法代码示例。如果您正苦于以下问题:Java CommandLine.getValues方法的具体用法?Java CommandLine.getValues怎么用?Java CommandLine.getValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.cli2.CommandLine
的用法示例。
在下文中一共展示了CommandLine.getValues方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: maybePut
import org.apache.commons.cli2.CommandLine; //导入方法依赖的package包/类
protected static void maybePut(Map<String, List<String>> args, CommandLine cmdLine, Option... opt) {
for (Option o : opt) {
// the option appeared on the command-line, or it has a value
// (which is likely a default value).
if (cmdLine.hasOption(o) || cmdLine.getValue(o) != null ||
(cmdLine.getValues(o) != null && !cmdLine.getValues(o).isEmpty())) {
// nulls are ok, for cases where options are simple flags.
List<?> vo = cmdLine.getValues(o);
if (vo != null && !vo.isEmpty()) {
List<String> vals = new ArrayList<String>();
for (Object o1 : vo) {
vals.add(o1.toString());
}
args.put(o.getPreferredName(), vals);
} else {
args.put(o.getPreferredName(), null);
}
}
}
}
示例2: main
import org.apache.commons.cli2.CommandLine; //导入方法依赖的package包/类
/**
*
* @param args
* command line arguments
* -
*/
public static void main(final String[] args) {
Parser parser = new Parser();
parser.setGroup(configureCommandLine());
CommandLine cli = null;
try {
cli = parser.parse(args);
if (cli.hasOption("--help")) {
printUsage(null);
}
//timeoutAsUnknown = cli.hasOption("--unknown");
String sHost = (String) cli.getValue("--host");
final Long port = (Long) cli.getValue("--port", Long.valueOf(DEFAULT_PORT));
String sCommand = (String) cli.getValue("--command", "_NRPE_CHECK");
JNRPEClient client = new JNRPEClient(sHost, port.intValue(), !cli.hasOption("--nossl"));
client.setTimeout(((Long) cli.getValue("--timeout", Long.valueOf(DEFAULT_TIMEOUT))).intValue());
if (cli.hasOption("--weakCiherSuites")) {
client.enableWeakCipherSuites();
}
@SuppressWarnings("unchecked")
List<String> argList = cli.getValues("--arglist");
ReturnValue ret = client.sendCommand(sCommand, argList.toArray(new String[argList.size()]));
System.out.println(ret.getMessage());
System.exit(ret.getStatus().intValue());
} catch (JNRPEClientException exc) {
Status returnStatus;
Throwable cause = exc.getCause();
if (cli.hasOption("--unknown") && cause instanceof SocketTimeoutException) {
returnStatus = Status.UNKNOWN;
} else {
returnStatus = Status.CRITICAL;
}
System.out.println(exc.getMessage());
System.exit(returnStatus.intValue());
} catch (OptionException oe) {
printUsage(oe);
}
}