• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Parser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.cli2.commandline.Parser的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Parser类属于org.apache.commons.cli2.commandline包,在下文中一共展示了Parser类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testNoArgumentsOption

import org.apache.commons.cli2.commandline.Parser; //导入依赖的package包/类
public void testNoArgumentsOption() throws Exception {
    ClassLoader cl = TestCommandLineParsing.class.getClassLoader();
    PluginDefinition pluginDef =
            PluginRepositoryUtil.parseXmlPluginDefinition(cl,
                    cl.getResourceAsStream("check_mysql_plugin.xml"));

    GroupBuilder gBuilder = new GroupBuilder();

    for (PluginOption po : pluginDef.getOptions()) {
        gBuilder = gBuilder.withOption(po.toOption());
    }

    Group group = gBuilder.create();
    Parser p = new Parser();
    p.setGroup(group);
    CommandLine cli =
            p.parse(new String[] { "--hostname", "$ARG1$", "--port",
                    "$ARG2$", "--database", "$ARG3$", "--user", "$ARG4$",
                    "--password", "$ARG5$", "--check-slave" });

    Assert.assertTrue(cli.hasOption("--check-slave"));
}
 
开发者ID:ziccardi,项目名称:jnrpe,代码行数:23,代码来源:TestCommandLineParsing.java


示例2: execute

import org.apache.commons.cli2.commandline.Parser; //导入依赖的package包/类
public boolean execute(final String[] args) throws Exception {

        Parser p = new Parser();
        p.setGroup(getCommandLineGroup());
        try {
            p.parse(args);
        } catch (Exception e) {
            getConsole().println();
            // getConsole().println("\u001B[1mERROR:\u001B[0m " +
            // e.getMessage());
            getConsole().println(highlight("ERROR: ") + e.getMessage());
            getConsole().println();

            printHelp();
            return false;
        }
        PluginProxy plugin = (PluginProxy) pluginRepository.getPlugin(pluginName);
        InjectionUtils.inject(plugin, context);
        //plugin.setContext(context);
        ReturnValue retVal = plugin.execute(args);

        getConsole().println(retVal.getMessage());
        return false;
    }
 
开发者ID:ziccardi,项目名称:jnrpe,代码行数:25,代码来源:PluginCommand.java


示例3: parseCommandLine

import org.apache.commons.cli2.commandline.Parser; //导入依赖的package包/类
/**
 * Parses the command line.
 * 
 * @param vsArgs
 *            The command line
 * @return The parsed command line
 */
private static CommandLine parseCommandLine(final String[] vsArgs) {
    try {
        Group opts = configureCommandLine();
        // configure a HelpFormatter
        HelpFormatter hf = new HelpFormatter();

        // configure a parser
        Parser p = new Parser();
        p.setGroup(opts);
        p.setHelpFormatter(hf);
        // p.setHelpTrigger("--help");
        return p.parse(vsArgs);
    } catch (OptionException oe) {
        printUsage(oe);
    } catch (Exception e) {
        e.printStackTrace();
        // Should never happen...
    }
    return null;
}
 
开发者ID:ziccardi,项目名称:jnrpe,代码行数:28,代码来源:JNRPEServer.java


示例4: main

import org.apache.commons.cli2.commandline.Parser; //导入依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
  DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
  ArgumentBuilder abuilder = new ArgumentBuilder();
  GroupBuilder gbuilder = new GroupBuilder();
  
  Option inputOpt = DefaultOptionCreator.inputOption().withRequired(false).create();
  Option outputOpt = DefaultOptionCreator.outputOption().withRequired(false).create();
  Option vectorOpt = obuilder.withLongName("vector").withRequired(false).withArgument(
    abuilder.withName("v").withMinimum(1).withMaximum(1).create()).withDescription(
    "The vector implementation to use.").withShortName("v").create();
  
  Option helpOpt = DefaultOptionCreator.helpOption();
  
  Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(outputOpt).withOption(
    vectorOpt).withOption(helpOpt).create();
	 
  try {
    Parser parser = new Parser();
    parser.setGroup(group);
    CommandLine cmdLine = parser.parse(args);
    if (cmdLine.hasOption(helpOpt)) {
      CommandLineUtil.printHelp(group);
      return;
    }
    
    Path input = new Path(cmdLine.getValue(inputOpt, "testdata").toString());
    Path output = new Path(cmdLine.getValue(outputOpt, "output").toString());
    String vectorClassName = cmdLine.getValue(vectorOpt,
       "org.apache.mahout.math.RandomAccessSparseVector").toString();
    //runJob(input, output, vectorClassName);
  } catch (OptionException e) {
    InputDriver.log.error("Exception parsing command line: ", e);
    CommandLineUtil.printHelp(group);
  }
}
 
开发者ID:PacktPublishing,项目名称:HBase-High-Performance-Cookbook,代码行数:36,代码来源:InputDriver.java


示例5: run

import org.apache.commons.cli2.commandline.Parser; //导入依赖的package包/类
@Override
 public int run(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
 // TODO Auto-generated method stub
   DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
   ArgumentBuilder abuilder = new ArgumentBuilder();
   GroupBuilder gbuilder = new GroupBuilder();

   Option inputOpt = DefaultOptionCreator.inputOption().create();

   Option datasetOpt = obuilder.withLongName("dataset").withShortName("ds").withRequired(true).withArgument(
      abuilder.withName("dataset").withMinimum(1).withMaximum(1).create()).withDescription("Dataset path")
        .create();

   Option modelOpt = obuilder.withLongName("model").withShortName("m").withRequired(true).withArgument(
        abuilder.withName("path").withMinimum(1).withMaximum(1).create()).
        withDescription("Path to the Model").create();

Option outputOpt = DefaultOptionCreator.outputOption().create();

Option helpOpt = DefaultOptionCreator.helpOption();

Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(datasetOpt).withOption(modelOpt)
        .withOption(outputOpt).withOption(helpOpt).create();

try {
  Parser parser = new Parser();
  parser.setGroup(group);
  CommandLine cmdLine = parser.parse(args);

  if (cmdLine.hasOption("help")) {
    CommandLineUtil.printHelp(group);
    return -1;
  }

  dataName = cmdLine.getValue(inputOpt).toString();
  String datasetName = cmdLine.getValue(datasetOpt).toString();
  String modelName = cmdLine.getValue(modelOpt).toString();
  String outputName = cmdLine.hasOption(outputOpt) ? cmdLine.getValue(outputOpt).toString() : null;
  
  if (log.isDebugEnabled()) {
    log.debug("inout     : {}", dataName);
    log.debug("dataset   : {}", datasetName);
    log.debug("model     : {}", modelName);
    log.debug("output    : {}", outputName);
  }

  dataPath = new Path(dataName);
  datasetPath = new Path(datasetName);
  modelPath = new Path(modelName);
  if (outputName != null) {
    outputPath = new Path(outputName);
  }
  
} catch (OptionException e) {
  
     log.warn(e.toString(), e);
  CommandLineUtil.printHelp(group);
  return -1;
  
}
    
time = System.currentTimeMillis();
    
testModel();
    
time = System.currentTimeMillis() - time;
    
writeToFileClassifyTime(Chi_RWCSUtils.elapsedTime(time));

   return 0;
 }
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:72,代码来源:TestModel.java


示例6: main

import org.apache.commons.cli2.commandline.Parser; //导入依赖的package包/类
public static void main(String[] args) throws IOException, DescriptorException {

    DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
    ArgumentBuilder abuilder = new ArgumentBuilder();
    GroupBuilder gbuilder = new GroupBuilder();

    Option pathOpt = obuilder.withLongName("path").withShortName("p").withRequired(true).withArgument(
        abuilder.withName("path").withMinimum(1).withMaximum(1).create()).withDescription("Data path").create();

    Option descriptorOpt = obuilder.withLongName("descriptor").withShortName("d").withRequired(true)
        .withArgument(abuilder.withName("descriptor").withMinimum(1).create()).withDescription(
            "data descriptor").create();

    Option descPathOpt = obuilder.withLongName("file").withShortName("f").withRequired(true).withArgument(
        abuilder.withName("file").withMinimum(1).withMaximum(1).create()).withDescription(
        "Path to generated descriptor file").create();

    Option regOpt = obuilder.withLongName("regression").withDescription("Regression Problem").withShortName("r")
        .create();

    Option helpOpt = obuilder.withLongName("help").withDescription("Print out help").withShortName("h")
        .create();

    Group group = gbuilder.withName("Options").withOption(pathOpt).withOption(descPathOpt).withOption(
        descriptorOpt).withOption(regOpt).withOption(helpOpt).create();

    try {
      Parser parser = new Parser();
      parser.setGroup(group);
      CommandLine cmdLine = parser.parse(args);

      if (cmdLine.hasOption(helpOpt)) {
        CommandLineUtil.printHelp(group);
        return;
      }

      String dataPath = cmdLine.getValue(pathOpt).toString();
      String descPath = cmdLine.getValue(descPathOpt).toString();
      List<String> descriptor = convert(cmdLine.getValues(descriptorOpt));
      boolean regression = cmdLine.hasOption(regOpt);

      log.debug("Data path : {}", dataPath);
      log.debug("Descriptor path : {}", descPath);
      log.debug("Descriptor : {}", descriptor);
      log.debug("Regression : {}", regression);

      runTool(dataPath, descriptor, descPath, regression);
    } catch (OptionException e) {
      log.warn(e.toString());
      CommandLineUtil.printHelp(group);
    }
  }
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:53,代码来源:Describe.java


示例7: run

import org.apache.commons.cli2.commandline.Parser; //导入依赖的package包/类
@Override
 public int run(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
 // TODO Auto-generated method stub
   DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
   ArgumentBuilder abuilder = new ArgumentBuilder();
   GroupBuilder gbuilder = new GroupBuilder();

   Option inputOpt = DefaultOptionCreator.inputOption().create();

   Option datasetOpt = obuilder.withLongName("dataset").withShortName("ds").withRequired(true).withArgument(
      abuilder.withName("dataset").withMinimum(1).withMaximum(1).create()).withDescription("Dataset path")
        .create();

   Option modelOpt = obuilder.withLongName("model").withShortName("m").withRequired(true).withArgument(
        abuilder.withName("path").withMinimum(1).withMaximum(1).create()).
        withDescription("Path to the Model").create();

Option outputOpt = DefaultOptionCreator.outputOption().create();

Option helpOpt = DefaultOptionCreator.helpOption();

Group group = gbuilder.withName("Options").withOption(inputOpt).withOption(datasetOpt).withOption(modelOpt)
        .withOption(outputOpt).withOption(helpOpt).create();

try {
  Parser parser = new Parser();
  parser.setGroup(group);
  CommandLine cmdLine = parser.parse(args);

  if (cmdLine.hasOption("help")) {
    CommandLineUtil.printHelp(group);
    return -1;
  }

  dataName = cmdLine.getValue(inputOpt).toString();
  String datasetName = cmdLine.getValue(datasetOpt).toString();
  String modelName = cmdLine.getValue(modelOpt).toString();
  String outputName = cmdLine.hasOption(outputOpt) ? cmdLine.getValue(outputOpt).toString() : null;
  
  if (log.isDebugEnabled()) {
    log.debug("inout     : {}", dataName);
    log.debug("dataset   : {}", datasetName);
    log.debug("model     : {}", modelName);
    log.debug("output    : {}", outputName);
  }

  dataPath = new Path(dataName);
  datasetPath = new Path(datasetName);
  modelPath = new Path(modelName);
  if (outputName != null) {
    outputPath = new Path(outputName);
  }
  
} catch (OptionException e) {
  
     log.warn(e.toString(), e);
  CommandLineUtil.printHelp(group);
  return -1;
  
}
    
time = System.currentTimeMillis();
    
testModel();
    
time = System.currentTimeMillis() - time;
    
writeToFileClassifyTime(Chi_RWUtils.elapsedTime(time));

   return 0;
 }
 
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigData-Ave,代码行数:72,代码来源:TestModel.java


示例8: main

import org.apache.commons.cli2.commandline.Parser; //导入依赖的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.Parser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DecoratedRandomTextPaster类代码示例发布时间:2022-05-22
下一篇:
Java InventoryTransactionResult类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap