本文整理汇总了Java中org.apache.commons.cli.PosixParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java PosixParser.parse方法的具体用法?Java PosixParser.parse怎么用?Java PosixParser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.cli.PosixParser
的用法示例。
在下文中一共展示了PosixParser.parse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.apache.commons.cli.PosixParser; //导入方法依赖的package包/类
/**
* Parses the command line options
*
* @return false if need to print help output
*
* @throws Exception
* when parsing fails
*/
ParsedOutput parse() throws Exception {
if (parsed == null) {
PosixParser parser = new PosixParser();
CommandLine popts = parser.parse(getOptionList(), argumentList, true);
if (popts.hasOption(ConfigOption.HELP.getOpt())) {
parsed = new ParsedOutput(null, this, true);
} else {
parsed = new ParsedOutput(popts, this, false);
}
}
return parsed;
}
示例2: getCommandLine
import org.apache.commons.cli.PosixParser; //导入方法依赖的package包/类
public static CommandLine getCommandLine( Options options, String[] args )
throws ParseException {
PosixParser parser = new PosixParser();
CommandLine cmd = parser.parse( options, args );
return cmd;
}
示例3: testOrder
import org.apache.commons.cli.PosixParser; //导入方法依赖的package包/类
@Test
public void testOrder() throws ParseException {
Option optionA = new Option("a", "first");
Options opts = new Options();
opts.addOption(optionA);
PosixParser posixParser = new PosixParser();
CommandLine line = posixParser.parse(opts, null);
assertFalse(line.hasOption(null));
}
示例4: buildCommandline
import org.apache.commons.cli.PosixParser; //导入方法依赖的package包/类
public static CommandLine buildCommandline(String[] args) {
final Options options = new Options();
Option opt = new Option("h", "help", false, "Print help");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("g", "consumerGroup", true, "Consumer Group Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("t", "topic", true, "Topic Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("s", "subscription", true, "subscription");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("f", "returnFailedHalf", true, "return failed result, for half message");
opt.setRequired(true);
options.addOption(opt);
PosixParser parser = new PosixParser();
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
if (commandLine.hasOption('h')) {
hf.printHelp("producer", options, true);
return null;
}
} catch (ParseException e) {
hf.printHelp("producer", options, true);
return null;
}
return commandLine;
}
示例5: processOptions
import org.apache.commons.cli.PosixParser; //导入方法依赖的package包/类
private static void processOptions(String[] args)
{
Options options = new Options();
Option opt = new Option("in", true,
"Input file oe-supported Use .sdf to specify the file type.");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("out", true,
"Output file oe-supported Use .sdf to specify the file type.");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("bin", true,
"bin definition. Use format \"bin_1_upperbound=bin_1_name|bin_2_upperbound=bin_2_name|bin_3_upperbound_=bin_3_name\"");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("dataTag", true,
"SD tag containing data for binning");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("binTag", true,
"SD tag used for storing bin names");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("ignoreModifier", false,
"ignore leading '><= ~'");
options.addOption(opt);
opt = new Option("h", false,
"print usage statement");
opt.setRequired(false);
options.addOption(opt);
PosixParser parser = new PosixParser();
CommandLine cl=null;
try {
cl = parser.parse(options, args);
} catch (Exception exp) {
// catch (ParseException exp) {
System.err.println(exp.getMessage());
exitWithHelp(options);
}
inFile = cl.getOptionValue("in");
outFile = cl.getOptionValue("out");
ignoreModifier = cl.hasOption("ignoreModifier");
String binDefinition=cl.getOptionValue("bin");
parseBins(binDefinition);
binTag=cl.getOptionValue("binTag");
dataTag=cl.getOptionValue("dataTag");
}
示例6: buildCommandline
import org.apache.commons.cli.PosixParser; //导入方法依赖的package包/类
public static CommandLine buildCommandline(String[] args) {
final Options options = new Options();
// ////////////////////////////////////////////////////
Option opt = new Option("h", "help", false, "Print help");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("g", "consumerGroup", true, "Consumer Group Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("t", "topic", true, "Topic Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("s", "subscription", true, "subscription");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("f", "returnFailedHalf", true, "return failed result, for half message");
opt.setRequired(true);
options.addOption(opt);
// ////////////////////////////////////////////////////
PosixParser parser = new PosixParser();
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
if (commandLine.hasOption('h')) {
hf.printHelp("producer", options, true);
return null;
}
}
catch (ParseException e) {
hf.printHelp("producer", options, true);
return null;
}
return commandLine;
}
示例7: buildCommandline
import org.apache.commons.cli.PosixParser; //导入方法依赖的package包/类
public static CommandLine buildCommandline(String[] args) {
final Options options = new Options();
// ////////////////////////////////////////////////////
Option opt = new Option("h", "help", false, "Print help");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("g", "producerGroup", true, "Producer Group Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("t", "topic", true, "Topic Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("a", "tags", true, "Tags Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("k", "keys", true, "Keys Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("c", "msgCount", true, "Message Count");
opt.setRequired(true);
options.addOption(opt);
// ////////////////////////////////////////////////////
PosixParser parser = new PosixParser();
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
if (commandLine.hasOption('h')) {
hf.printHelp("producer", options, true);
return null;
}
}
catch (ParseException e) {
hf.printHelp("producer", options, true);
return null;
}
return commandLine;
}
示例8: buildCommandline
import org.apache.commons.cli.PosixParser; //导入方法依赖的package包/类
public static CommandLine buildCommandline(String[] args) {
final Options options = new Options();
Option opt = new Option("h", "help", false, "Print help");
opt.setRequired(false);
options.addOption(opt);
opt = new Option("g", "producerGroup", true, "Producer Group Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("t", "topic", true, "Topic Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("a", "tags", true, "Tags Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("k", "keys", true, "Keys Name");
opt.setRequired(true);
options.addOption(opt);
opt = new Option("c", "msgCount", true, "Message Count");
opt.setRequired(true);
options.addOption(opt);
PosixParser parser = new PosixParser();
HelpFormatter hf = new HelpFormatter();
hf.setWidth(110);
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
if (commandLine.hasOption('h')) {
hf.printHelp("producer", options, true);
return null;
}
} catch (ParseException e) {
hf.printHelp("producer", options, true);
return null;
}
return commandLine;
}