本文整理汇总了Java中org.apache.commons.cli2.Group类的典型用法代码示例。如果您正苦于以下问题:Java Group类的具体用法?Java Group怎么用?Java Group使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Group类属于org.apache.commons.cli2包,在下文中一共展示了Group类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testNoArgumentsOption
import org.apache.commons.cli2.Group; //导入依赖的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: getCommandLine
import org.apache.commons.cli2.Group; //导入依赖的package包/类
public String getCommandLine() {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Group g = getCommandLineGroup();
HelpFormatter hf = new HelpFormatter(null, null, null, getConsole().getTerminal().getWidth());
hf.setGroup(g);
hf.setPrintWriter(new PrintWriter(new OutputStreamWriter(bout, charset)));
hf.printUsage();
String usage = new String(bout.toByteArray(), charset);
String[] lines = usage.split("\\n");
StringBuilder res = new StringBuilder();
for (int i = 1; i < lines.length; i++) {
res.append(lines[i]);
}
return res.toString();
}
开发者ID:ziccardi,项目名称:jnrpe,代码行数:22,代码来源:PluginCommand.java
示例3: printHelp
import org.apache.commons.cli2.Group; //导入依赖的package包/类
public void printHelp() throws IOException {
Group g = getCommandLineGroup();
ByteArrayOutputStream bout = new ByteArrayOutputStream();
HelpFormatter hf = new HelpFormatter(" ", null, null, getConsole().getTerminal().getWidth());
hf.setGroup(g);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(bout, charset));
hf.setPrintWriter(pw);
hf.printHelp();
pw.flush();
// getConsole().println("\u001B[1mCommand Line:\u001B[0m ");
getConsole().println(highlight("Command Line: "));
getConsole().println(" " + getName() + " " + getCommandLine());
getConsole().println(highlight("Usage:"));
getConsole().println(new String(bout.toByteArray(), charset));
}
开发者ID:ziccardi,项目名称:jnrpe,代码行数:21,代码来源:PluginCommand.java
示例4: parseCommandLine
import org.apache.commons.cli2.Group; //导入依赖的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
示例5: main
import org.apache.commons.cli2.Group; //导入依赖的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
示例6: printHelpWithGenericOptions
import org.apache.commons.cli2.Group; //导入依赖的package包/类
/**
* Print the options supported by {@code GenericOptionsParser}.
* In addition to the options supported by the job, passed in as the
* group parameter.
*
* @param group job-specific command-line options.
*/
public static void printHelpWithGenericOptions(Group group) throws IOException {
new GenericOptionsParser(new Configuration(), new org.apache.commons.cli.Options(), new String[0]);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, Charsets.UTF_8), true);
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.setPrintWriter(pw);
formatter.setFooter("Specify HDFS directories while running on hadoop; else specify local file system directories");
formatter.print();
}
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:17,代码来源:CommandLineUtil.java
示例7: getCommandLineGroup
import org.apache.commons.cli2.Group; //导入依赖的package包/类
private Group getCommandLineGroup() {
PluginProxy pp = (PluginProxy) plugin;
GroupBuilder gBuilder = new GroupBuilder();
for (PluginOption po : pp.getOptions()) {
gBuilder = gBuilder.withOption(toOption(po));
}
return gBuilder.create();
}
开发者ID:ziccardi,项目名称:jnrpe,代码行数:11,代码来源:PluginCommand.java
示例8: configureCommandLine
import org.apache.commons.cli2.Group; //导入依赖的package包/类
/**
* Configure the command line parser.
*
* @return The configuration
*/
private static Group configureCommandLine() {
DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
ArgumentBuilder aBuilder = new ArgumentBuilder();
GroupBuilder gBuilder = new GroupBuilder();
DefaultOption listOption = oBuilder.withLongName("list").withShortName("l").withDescription("Lists all the installed plugins").create();
DefaultOption versionOption = oBuilder.withLongName("version").withShortName("v").withDescription("Print the server version number").create();
DefaultOption helpOption = oBuilder.withLongName("help").withShortName("h").withDescription("Show this help").create();
// DefaultOption pluginNameOption = oBuilder.withLongName("plugin")
// .withShortName("p").withDescription("The plugin name")
// .withArgument(
// aBuilder.withName("name").withMinimum(1).withMaximum(1)
// .create()).create();
DefaultOption pluginHelpOption = oBuilder.withLongName("help").withShortName("h").withDescription("Shows help about a plugin")
.withArgument(aBuilder.withName("name").withMinimum(1).withMaximum(1).create()).create();
Group alternativeOptions = gBuilder.withOption(listOption).withOption(pluginHelpOption).create();
DefaultOption confOption = oBuilder.withLongName("conf").withShortName("c").withDescription("Specifies the JNRPE configuration file")
.withArgument(aBuilder.withName("path").withMinimum(1).withMaximum(1).create()).withChildren(alternativeOptions).withRequired(true)
.create();
DefaultOption interactiveOption = oBuilder.withLongName("interactive").withShortName("i")
.withDescription("Starts JNRPE in command line mode").create();
Group jnrpeOptions = gBuilder.withOption(confOption).withOption(interactiveOption).withMinimum(1).create();
return gBuilder.withOption(versionOption).withOption(helpOption).withOption(jnrpeOptions).create();
}
开发者ID:ziccardi,项目名称:jnrpe,代码行数:39,代码来源:JNRPEServer.java
示例9: run
import org.apache.commons.cli2.Group; //导入依赖的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
示例10: main
import org.apache.commons.cli2.Group; //导入依赖的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
示例11: getGroup
import org.apache.commons.cli2.Group; //导入依赖的package包/类
protected Group getGroup() {
return group;
}
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:4,代码来源:AbstractJob.java
示例12: printHelp
import org.apache.commons.cli2.Group; //导入依赖的package包/类
public static void printHelp(Group group) {
HelpFormatter formatter = new HelpFormatter();
formatter.setGroup(group);
formatter.print();
}
开发者ID:saradelrio,项目名称:Chi-FRBCS-BigDataCS,代码行数:6,代码来源:CommandLineUtil.java
示例13: run
import org.apache.commons.cli2.Group; //导入依赖的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
示例14: configureCommandLine
import org.apache.commons.cli2.Group; //导入依赖的package包/类
/**
* Configures the command line parser.
*
* @return The command line parser configuration
*/
private static Group configureCommandLine() {
DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
ArgumentBuilder aBuilder = new ArgumentBuilder();
GroupBuilder gBuilder = new GroupBuilder();
DefaultOption nosslOption = oBuilder.withLongName("nossl").withShortName("n").withDescription("Do no use SSL").create();
DefaultOption weakSslOption = oBuilder.withLongName("weakCiherSuites").withShortName("w").withDescription("Enable weak cipher suites").create();
DefaultOption unknownOption = oBuilder.withLongName("unknown").withShortName("u")
.withDescription("Make socket timeouts return an UNKNOWN state instead of CRITICAL").create();
DefaultOption hostOption = oBuilder.withLongName("host").withShortName("H")
.withDescription("The address of the host running the JNRPE/NRPE daemon")
.withArgument(aBuilder.withName("host").withMinimum(1).withMaximum(1).create()).create();
NumberValidator positiveInt = NumberValidator.getIntegerInstance();
positiveInt.setMinimum(0);
DefaultOption portOption = oBuilder
.withLongName("port")
.withShortName("p")
.withDescription("The port on which the daemon is running (default=5666)")
.withArgument(
aBuilder.withName("port").withMinimum(1).withMaximum(1).withDefault(Long.valueOf(DEFAULT_PORT)).withValidator(positiveInt)
.create()).create();
DefaultOption timeoutOption = oBuilder
.withLongName("timeout")
.withShortName("t")
.withDescription("Number of seconds before connection times out (default=10)")
.withArgument(
aBuilder.withName("timeout").withMinimum(1).withMaximum(1).withDefault(Long.valueOf(DEFAULT_TIMEOUT))
.withValidator(positiveInt).create()).create();
DefaultOption commandOption = oBuilder
.withLongName("command")
.withShortName("c")
.withDescription("The name of the command that the remote daemon should run")
.withArgument(
aBuilder
.withName("command")
.withMinimum(1)
.withMaximum(1).create()
)
.create();
DefaultOption argsOption = oBuilder
.withLongName("arglist")
.withShortName("a")
.withDescription(
"Optional arguments that should be passed to the command. Multiple arguments should be separated by "
+ "a space (' '). If provided, this must be the last option supplied on the command line.")
.withArgument(aBuilder.withName("arglist").withMinimum(1).create()).create();
DefaultOption helpOption = oBuilder.withLongName("help").withShortName("h").withDescription("Shows this help").create();
Group executionOption = gBuilder
.withOption(nosslOption)
.withOption(weakSslOption)
.withOption(unknownOption)
.withOption(hostOption)
.withOption(portOption)
.withOption(timeoutOption)
.withOption(commandOption)
.withOption(argsOption).create();
return gBuilder.withOption(executionOption).withOption(helpOption).withMinimum(1).withMaximum(1).create();
}
开发者ID:ziccardi,项目名称:jnrpe,代码行数:74,代码来源:JNRPEClient.java
注:本文中的org.apache.commons.cli2.Group类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论