當前位置: 首頁>>代碼示例>>Java>>正文


Java CmdLineParser類代碼示例

本文整理匯總了Java中org.kohsuke.args4j.CmdLineParser的典型用法代碼示例。如果您正苦於以下問題:Java CmdLineParser類的具體用法?Java CmdLineParser怎麽用?Java CmdLineParser使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CmdLineParser類屬於org.kohsuke.args4j包,在下文中一共展示了CmdLineParser類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startApplication

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
@Override
protected void startApplication(final CmdLineParser parser) throws Exception {
    final List<String> lines = FileUtils.readLines(input, Charset.defaultCharset());
    final List<List<Double>> tradesPerStrategy = new ArrayList<List<Double>>(lines.size());
    for (final String line : lines) {
        final String[] tradeStrs = Strings.split(line, ",");
        final List<Double> trades = new ArrayList<Double>(tradeStrs.length);
        for (final String tradeStr : tradeStrs) {
            trades.add(Double.parseDouble(tradeStr));
        }
        tradesPerStrategy.add(trades);
    }
    final List<Double> optimalFs = new OptimalfScriptTask(tradesPerStrategy).run();
    final StringBuilder optimalFsStr = new StringBuilder();
    for (final Double optimalF : optimalFs) {
        optimalFsStr.append(optimalF);
        optimalFsStr.append("\n");
    }
    FileUtils.writeStringToFile(output, optimalFsStr.toString(), Charset.defaultCharset());
}
 
開發者ID:subes,項目名稱:invesdwin-context-r,代碼行數:21,代碼來源:Main.java

示例2: create

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
/**
 * Parse the CLI arguments and return the populated parameters structure.
 *
 * @param args the CLI arguments
 * @return the parsed parameters, or null if failed
 * @throws org.kohsuke.args4j.CmdLineException if cmd line is malformed
 */
public static CLI create (final String... args)
        throws CmdLineException
{
    logger.info("CLI args: {}", Arrays.toString(args));

    CLI cli = new CLI();

    final CmdLineParser parser = new CmdLineParser(cli);

    parser.parseArgument(args);

    if (args.length == 0) {
        cli.help = true;
    }

    if (cli.help) {
        printUsage(parser);
    }

    return cli;
}
 
開發者ID:Audiveris,項目名稱:omr-dataset-tools,代碼行數:29,代碼來源:CLI.java

示例3: printUsage

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
/**
 * Print out the general syntax for the command line.
 */
private static void printUsage (CmdLineParser parser)
{
    StringBuilder buf = new StringBuilder();

    buf.append("\n");
    buf.append("\nSyntax:");
    buf.append("\n   [OPTIONS] -- [INPUT_FILES]\n");

    buf.append("\[email protected]:");
    buf.append("\n Content to be extended in line");
    buf.append("\n");

    buf.append("\nOptions:\n");

    StringWriter writer = new StringWriter();
    parser.printUsage(writer, null);
    buf.append(writer.toString());

    buf.append("\nInput file extensions:");
    buf.append("\n .xml: annotations file");
    buf.append("\n");
    logger.info(buf.toString());
}
 
開發者ID:Audiveris,項目名稱:omr-dataset-tools,代碼行數:27,代碼來源:CLI.java

示例4: main

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
public static void main(final String[] args) {
    try {
        final MainArgs mainArgs = new MainArgs();

        new CmdLineParser(mainArgs).parseArgument(args);

        if (mainArgs.isHelp()) {
            printUsage();
        } else if (mainArgs.isVersion()) {
            printVersion();
        } else {
            Guice.createInjector(new EndPointHealthModule())
                    .getInstance(Main.class).run(mainArgs);
        }
    } catch (final CmdLineException e) {
        System.err.println(e.getMessage());
        printUsage();
    }
}
 
開發者ID:spypunk,項目名稱:endpoint-health,代碼行數:20,代碼來源:Main.java

示例5: main

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
    Consumer consumer = new Consumer();
    CmdLineParser parser = new CmdLineParser(consumer);

    try {
        parser.parseArgument(args);
    } catch (CmdLineException ce) {
        System.err.println(ce.getMessage());
        System.err.println();
        System.err.println(" Options are:");
        parser.printUsage(System.err); // print the list of available options
        System.err.println();
        System.exit(0);
    }

    consumer.run();
}
 
開發者ID:javaronok,項目名稱:kafka-mgd-sample,代碼行數:18,代碼來源:Consumer.java

示例6: main

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
public static void main(String[] args) throws IOException {
    Producer producer = new Producer();
    CmdLineParser parser = new CmdLineParser(producer);

    try {
        parser.parseArgument(args);
    } catch (CmdLineException ce) {
        System.err.println(ce.getMessage());
        System.err.println();
        System.err.println(" Options are:");
        parser.printUsage(System.err); // print the list of available options
        System.err.println();
        System.exit(0);
    }

    producer.run();
}
 
開發者ID:javaronok,項目名稱:kafka-mgd-sample,代碼行數:18,代碼來源:Producer.java

示例7: doMain

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
private void doMain(final String[] arguments) throws IOException
{
   final CmdLineParser parser = new CmdLineParser(this);
   if (arguments.length < 1)
   {
      parser.printUsage(out);
      System.exit(-1);
   }
   try
   {
      parser.parseArgument(arguments);
   }
   catch (CmdLineException clEx)
   {
      out.println("ERROR: Unable to parse command-line options: " + clEx);
   }
   out.println("The file '" + fileName + "' was provided and verbosity is set to '" + verbose + "'.");
}
 
開發者ID:dustinmarx,項目名稱:java-cli-demos,代碼行數:19,代碼來源:Main.java

示例8: printUsage

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
private void printUsage(PrintWriter writer) {
    // fix defaults for options like help and other 0-arg booleans
    OptionHandlerRegistry.getRegistry().registerHandler(Boolean.class, BooleanNoDefOptionHandler.class);
    OptionHandlerRegistry.getRegistry().registerHandler(boolean.class, BooleanNoDefOptionHandler.class);

    ParserProperties prop = ParserProperties.defaults()
            .withUsageWidth(80)
            .withOptionSorter(null);

    ByteArrayOutputStream buf = new ByteArrayOutputStream();

    // new args instance to get correct defaults
    new CmdLineParser(new CliArgs(), prop)
    .printUsage(new OutputStreamWriter(buf, StandardCharsets.UTF_8), null);

    writer.println(MessageFormat.format(Messages.UsageHelp.replace("${tab}", "\t"),
            new String(buf.toByteArray(), StandardCharsets.UTF_8),
            DangerStatementOptionHandler.getMetaVariable() + '\n' + DbObjTypeOptionHandler.getMetaVariable()));
}
 
開發者ID:pgcodekeeper,項目名稱:pgcodekeeper,代碼行數:20,代碼來源:CliArgs.java

示例9: parse

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
/** Parse the command line options. 
 * @param args the command line args as passed to the main method of the
 * program.
 * @return the parsed command line options or {@code null} if
 * the program needs to exit. {@code null} will be returned
 * if the command lines are wrong or the command line help
 * was displayed.
 */
public static Params parse(String[] args) {
    Params result = new Params();
    CmdLineParser cmdLineParser = new CmdLineParser(result);
    try {
        if (log.isDebugEnabled()) {
            log.debug("Args: {}", Arrays.toString(args));
        }
        
        cmdLineParser.parseArgument(args);
        
        if (result.help) {
            cmdLineParser.printUsage(System.err);
            return null;
        }
                    
        return result;
    } catch (CmdLineException ex) {
        log.warn("Error in parsing", ex);
        System.err.println(ex.getMessage());
        cmdLineParser.printUsage(System.err);
    }
    return null;
}
 
開發者ID:1and1,項目名稱:cli-skeleton,代碼行數:32,代碼來源:Params.java

示例10: doMain

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
private void doMain(
        String[] args) {
    CmdLineParser parser = new CmdLineParser(this);
    try {
        parser.parseArgument(args);
        ensureResultXmlDirectory();

        generateDonutJsonFiles();

    }catch (CmdLineException c){
        System.err.println(c.getMessage());
        System.err.println("usage: Main [options ...]");
        parser.printUsage(System.err);
        System.exit(1);
    }catch (Exception e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
 
開發者ID:DonutReport,項目名稱:donut-nunit-adapter,代碼行數:20,代碼來源:Main.java

示例11: startApplication

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
@Override
protected void startApplication(final CmdLineParser parser) throws Exception {
    final List<String> lines = FileUtils.readLines(input, Charset.defaultCharset());
    final List<List<Double>> tradesPerStrategy = new ArrayList<List<Double>>(lines.size());
    for (final String line : lines) {
        final String[] tradeStrs = Strings.split(line, ",");
        final List<Double> trades = new ArrayList<Double>(tradeStrs.length);
        for (final String tradeStr : tradeStrs) {
            trades.add(Double.parseDouble(tradeStr));
        }
        tradesPerStrategy.add(trades);
    }
    final List<Double> optimalFs = new OrnsteinUhlenbeckScriptTask(tradesPerStrategy).run();
    final StringBuilder optimalFsStr = new StringBuilder();
    for (final Double optimalF : optimalFs) {
        optimalFsStr.append(optimalF);
        optimalFsStr.append("\n");
    }
    FileUtils.writeStringToFile(output, optimalFsStr.toString(), Charset.defaultCharset());
}
 
開發者ID:subes,項目名稱:invesdwin-context-matlab,代碼行數:21,代碼來源:Main.java

示例12: testCreatePipelineBuilder_Sql

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
@Test
public void testCreatePipelineBuilder_Sql() throws Exception {
    // Given
    Main main = new Main();
    CmdLineParser cmdLineParser = new CmdLineParser(main);
    cmdLineParser.parseArgument(
        "--type", "sql",
        "--url", "jdbc:h2:mem:test",
        "--username", "sa",
        "--files", "target/test-classes/com/github/gquintana/beepbeep/**/*.sql");
    // When
    PipelineBuilder pipelineBuilder = main.createPipelineBuilder();
    // Then
    assertThat(main.url).isEqualTo("jdbc:h2:mem:test");
    assertThat(pipelineBuilder).isInstanceOf(SqlPipelineBuilder.class);

}
 
開發者ID:gquintana,項目名稱:beepbeep,代碼行數:18,代碼來源:MainTest.java

示例13: testCreatePipelineBuilder_SqlConfiguration

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
@Test
public void testCreatePipelineBuilder_SqlConfiguration() throws Exception {
    // Given
    File configFile = new File(temporaryFolder.getRoot(), "sql.yml");
    TestFiles.writeResource("config/sql1.yml", configFile);
    Main main = new Main();
    CmdLineParser cmdLineParser = new CmdLineParser(main);
    cmdLineParser.parseArgument(
        "--config", configFile.getPath());
    // When
    PipelineBuilder pipelineBuilder = main.createPipelineBuilder();
    // Then
    assertThat(pipelineBuilder).isInstanceOf(SqlPipelineBuilder.class);
    assertThat(getField(pipelineBuilder, "url")).isEqualTo("jdbc:h2:mem:test");

}
 
開發者ID:gquintana,項目名稱:beepbeep,代碼行數:17,代碼來源:MainTest.java

示例14: main

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
public static void main(String[] args) throws ClassNotFoundException {

        // https://martin-thoma.com/how-to-parse-command-line-arguments-in-java/
        EBoardRender.Config config = new EBoardRender.Config();

        CmdLineParser parser = new CmdLineParser(  config );
        try {
            parser.parseArgument(args);
        } catch (CmdLineException e) {
            e.printStackTrace();
        }

        Configuration conf = Configuration.getInstance(config.getConfig());
            String command = conf.getCommand().trim().toUpperCase();
            CommandHandler commandHandler = conf.getCommandHandlerFactory().getCommandHandler(command);
            commandHandler.execute(conf);
    }
 
開發者ID:eamonfoy,項目名稱:trello-to-markdown,代碼行數:18,代碼來源:EBoardRender.java

示例15: parseArguments

import org.kohsuke.args4j.CmdLineParser; //導入依賴的package包/類
private void parseArguments(String[] args) {
    CmdLineParser parser = new CmdLineParser(this);

    try {
        parser.parseArgument(args);
    } catch (CmdLineException e) {
        // if there's a problem in the command line,
        // you'll get this exception. this will report
        // an error message.
        System.err.println(e.getMessage());
        System.err.println("java -jar reddit-history.jar [options...] arguments...");
        // print the list of available options
        parser.printUsage(System.err);
        System.err.println();
        System.exit(0);

        return;
    }
}
 
開發者ID:dessalines,項目名稱:flowchat,代碼行數:20,代碼來源:ChatService.java


注:本文中的org.kohsuke.args4j.CmdLineParser類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。