本文整理汇总了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());
}
示例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;
}
示例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());
}
示例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();
}
}
示例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();
}
示例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();
}
示例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 + "'.");
}
示例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()));
}
示例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;
}
示例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);
}
}
示例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());
}
示例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);
}
示例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");
}
示例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);
}
示例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;
}
}