当前位置: 首页>>代码示例>>Java>>正文


Java CommandLine.getValues方法代码示例

本文整理汇总了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);
      }
    }
  }
}
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:23,代码来源:AbstractJob.java

示例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);
    }
}
 
开发者ID:ziccardi,项目名称:jnrpe,代码行数:56,代码来源:JNRPEClient.java


注:本文中的org.apache.commons.cli2.CommandLine.getValues方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。