本文整理了Java中org.apache.commons.cli.Option.getArgs()
方法的一些代码示例,展示了Option.getArgs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.getArgs()
方法的具体详情如下:
包路径:org.apache.commons.cli.Option
类名称:Option
方法名:getArgs
[英]Returns the number of argument values this Option can take.
[中]返回此选项可以接受的参数值的数目。
代码示例来源:origin: commons-cli/commons-cli
/**
* Check if the specified token is a Java-like property (-Dkey=value).
*/
private boolean isJavaProperty(String token)
{
String opt = token.substring(0, 1);
Option option = options.getOption(opt);
return option != null && (option.getArgs() >= 2 || option.getArgs() == Option.UNLIMITED_VALUES);
}
代码示例来源:origin: commons-cli/commons-cli
@Test
public void testOptionArgNumbers()
{
Option opt = OptionBuilder.withDescription( "option description" )
.hasArgs( 2 )
.create( 'o' );
assertEquals( 2, opt.getArgs() );
}
代码示例来源:origin: commons-cli/commons-cli
private static void checkOption(Option option, String opt, String description, String longOpt, int numArgs,
String argName, boolean required, boolean optionalArg,
char valueSeparator, Class<?> cls)
{
assertEquals(opt, option.getOpt());
assertEquals(description, option.getDescription());
assertEquals(longOpt, option.getLongOpt());
assertEquals(numArgs, option.getArgs());
assertEquals(argName, option.getArgName());
assertEquals(required, option.isRequired());
assertEquals(optionalArg, option.hasOptionalArg());
assertEquals(valueSeparator, option.getValueSeparator());
assertEquals(cls, option.getType());
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Check if the specified token is a Java-like property (-Dkey=value).
*/
private boolean isJavaProperty(String token)
{
String opt = token.substring(0, 1);
Option option = options.getOption(opt);
return option != null && (option.getArgs() >= 2 || option.getArgs() == Option.UNLIMITED_VALUES);
}
代码示例来源:origin: com.github.markusbernhardt/xml-doclet
/**
* Check for doclet-added options. Returns the number of arguments you must
* specify on the command line for the given option. For example, "-d docs"
* would return 2.
* <P>
* This method is required if the doclet contains any options. If this
* method is missing, Javadoc will print an invalid flag error for every
* option.
*
* @see com.sun.javadoc.Doclet#optionLength(String)
*
* @param optionName
* The name of the option.
* @return number of arguments on the command line for an option including
* the option name itself. Zero return means option not known.
* Negative value means error occurred.
*/
public static int optionLength(String optionName) {
Option option = options.getOption(optionName);
if (option == null) {
return 0;
}
return option.getArgs() + 1;
}
代码示例来源:origin: org.apache.helix/helix-core
private static boolean checkOptionArgsNumber(Option[] options) {
for (Option option : options) {
int argNb = option.getArgs();
String[] args = option.getValues();
if (argNb == 0) {
if (args != null && args.length > 0) {
System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
+ Arrays.toString(args) + ")");
return false;
}
} else {
if (args == null || args.length != argNb) {
System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
+ Arrays.toString(args) + ")");
return false;
}
}
}
return true;
}
代码示例来源:origin: apache/helix
private static boolean checkOptionArgsNumber(Option[] options) {
for (Option option : options) {
int argNb = option.getArgs();
String[] args = option.getValues();
if (argNb == 0) {
if (args != null && args.length > 0) {
System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
+ Arrays.toString(args) + ")");
return false;
}
} else {
if (args == null || args.length != argNb) {
System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
+ Arrays.toString(args) + ")");
return false;
}
}
}
return true;
}
代码示例来源:origin: org.apache.helix/helix-core
/** Ensures options argument counts are correct */
private static boolean checkOptionArgsNumber(Option[] options) {
for (Option option : options) {
int argNb = option.getArgs();
String[] args = option.getValues();
if (argNb == 0) {
if (args != null && args.length > 0) {
System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
+ Arrays.toString(args) + ")");
return false;
}
} else {
if (args == null || args.length != argNb) {
System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
+ Arrays.toString(args) + ")");
return false;
}
}
}
return true;
}
代码示例来源:origin: apache/helix
/** Ensures options argument counts are correct */
private static boolean checkOptionArgsNumber(Option[] options) {
for (Option option : options) {
int argNb = option.getArgs();
String[] args = option.getValues();
if (argNb == 0) {
if (args != null && args.length > 0) {
System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
+ Arrays.toString(args) + ")");
return false;
}
} else {
if (args == null || args.length != argNb) {
System.err.println(option.getArgName() + " shall have " + argNb + " arguments (was "
+ Arrays.toString(args) + ")");
return false;
}
}
}
return true;
}
代码示例来源:origin: com.palantir.atlasdb/atlasdb-dropwizard-bundle
@Override
public void configure(Subparser subparser) {
for (Option option : (Collection<Option>) AtlasConsoleMain.OPTIONS.getOptions()) {
int numArgs = option.getArgs();
if (option.getOpt().equals("h")) {
continue;
}
Argument arg = subparser.addArgument("-" + option.getOpt(), "--" + option.getLongOpt())
.required(option.isRequired())
.help(option.getDescription())
.dest("--" + option.getLongOpt());
if (numArgs == Option.UNLIMITED_VALUES) {
arg.nargs("+");
} else if (numArgs != Option.UNINITIALIZED) {
arg.nargs(numArgs);
}
}
addOfflineParameter(subparser);
super.configure(subparser);
}
代码示例来源:origin: iterate-ch/cyberduck
public boolean validate(final CommandLine input) {
for(Option o : input.getOptions()) {
if(Option.UNINITIALIZED == o.getArgs()) {
continue;
continue;
if(o.getArgs() != o.getValuesList().size()) {
console.printf("Missing argument for option %s%n", o.getLongOpt());
return false;
代码示例来源:origin: com.marklogic/mlcp
public CommandlineOption(Option opt)
throws IllegalArgumentException {
super(opt.getOpt(), opt.hasArg(), opt.getDescription());
this.setLongOpt(opt.getLongOpt());
this.setRequired(opt.isRequired());
this.setArgName(opt.getArgName());
this.setArgs(opt.getArgs());
this.setOptionalArg(opt.hasOptionalArg());
this.setType(opt.getType());
this.setValueSeparator(opt.getValueSeparator());
}
代码示例来源:origin: EMCECS/ecs-sync
private void assertOption(org.apache.commons.cli.Option option, String longOpt, boolean required, int args, String argName) {
Assert.assertNull(option.getOpt());
Assert.assertEquals(longOpt, option.getLongOpt());
Assert.assertEquals(required, option.isRequired());
Assert.assertEquals(args, option.getArgs());
Assert.assertEquals(argName, option.getArgName());
}
内容来源于网络,如有侵权,请联系作者删除!