本文整理了Java中org.apache.commons.cli.Option.getValue()
方法的一些代码示例,展示了Option.getValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.getValue()
方法的具体详情如下:
包路径:org.apache.commons.cli.Option
类名称:Option
方法名:getValue
[英]Returns the specified value of this Option or null
if there is no value.
[中]返回此选项的指定值,如果没有值,则返回null
。
代码示例来源:origin: commons-cli/commons-cli
/**
* Returns the value/first value of this Option or the
* <code>defaultValue</code> if there is no value.
*
* @param defaultValue The value to be returned if there
* is no value.
*
* @return the value/first value of this Option or the
* <code>defaultValue</code> if there are no values.
*/
public String getValue(String defaultValue)
{
String value = getValue();
return (value != null) ? value : defaultValue;
}
代码示例来源:origin: jmxtrans/jmxtrans
configuration.setContinueOnJsonError(Boolean.parseBoolean(option.getValue()));
} else if (option.getOpt().equals("j")) {
File jsonDir = new File(option.getValue());
if (jsonDir.exists() && jsonDir.isDirectory()) {
configuration.setProcessConfigDir(jsonDir);
File jsonFile = new File(option.getValue());
if (jsonFile.exists() && jsonFile.isFile()) {
configuration.setProcessConfigFile(jsonFile);
} else if (option.getOpt().equals("s")) {
try {
configuration.setRunPeriod(Integer.parseInt(option.getValue()));
} catch (NumberFormatException nfe) {
throw new OptionsException("Seconds between server job runs must be an integer");
代码示例来源:origin: commons-cli/commons-cli
@Override
public String getValue()
{
return super.getValue() != null ? super.getValue() : defaultValue;
}
}
代码示例来源:origin: apache/kylin
public String getOptionsAsString() {
StringBuilder buf = new StringBuilder();
for (Option option : commandLine.getOptions()) {
buf.append(" ");
buf.append(option.getOpt());
if (option.hasArg()) {
buf.append("=");
buf.append(option.getValue());
}
}
return buf.toString();
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Builds an instance of T using the selected constructor getting the constructor
* parameters from the {@link CommandLine}.
*
* Note: this method will also automatically call {@link #applyCommandLineOptions(CommandLine, T)} on
* the constructed object.
*/
private T buildInstance(CommandLine cli) {
String[] constructorArgs = new String[this.constructor.getParameterTypes().length];
for (Option option : cli.getOptions()) {
if (this.constructoArgumentsMap.containsKey(option.getOpt())) {
int idx = this.constructoArgumentsMap.get(option.getOpt());
constructorArgs[idx] = option.getValue();
}
}
T embeddedGobblin;
try {
embeddedGobblin = this.constructor.newInstance((Object[]) constructorArgs);
return embeddedGobblin;
} catch (IllegalAccessException | InvocationTargetException | InstantiationException exc) {
throw new RuntimeException("Could not instantiate " + this.klazz.getName(), exc);
}
}
代码示例来源:origin: apache/incubator-gobblin
/**
* For each method for which the helper created an {@link Option} and for which the input {@link CommandLine} contains
* that option, this method will automatically call the method on the input object with the correct
* arguments.
*/
public void applyCommandLineOptions(CommandLine cli, T embeddedGobblin) {
try {
for (Option option : cli.getOptions()) {
if (!this.methodsMap.containsKey(option.getOpt())) {
// Option added by cli driver itself.
continue;
}
if (option.hasArg()) {
this.methodsMap.get(option.getOpt()).invoke(embeddedGobblin, option.getValue());
} else {
this.methodsMap.get(option.getOpt()).invoke(embeddedGobblin);
}
}
} catch (IllegalAccessException | InvocationTargetException exc) {
throw new RuntimeException("Could not apply options to " + embeddedGobblin.getClass().getName(), exc);
}
}
代码示例来源:origin: apache/flink
/**
* Returns {@link ParameterTool} for the arguments parsed by {@link GenericOptionsParser}.
*
* @param args Input array arguments. It should be parsable by {@link GenericOptionsParser}
* @return A {@link ParameterTool}
* @throws IOException If arguments cannot be parsed by {@link GenericOptionsParser}
* @see GenericOptionsParser
*/
public static ParameterTool paramsFromGenericOptionsParser(String[] args) throws IOException {
Option[] options = new GenericOptionsParser(args).getCommandLine().getOptions();
Map<String, String> map = new HashMap<String, String>();
for (Option option : options) {
String[] split = option.getValue().split("=");
map.put(split[0], split[1]);
}
return ParameterTool.fromMap(map);
}
}
代码示例来源:origin: Alluxio/alluxio
Map<String, String> optionsMap = new HashMap<>();
for (Option opt : cmd.getOptions()) {
optionsMap.put(opt.getOpt(), opt.getValue());
代码示例来源:origin: internetarchive/heritrix3
prefix = cmdlineOptions[i].getValue();
break;
suffix = cmdlineOptions[i].getValue();
break;
代码示例来源:origin: commons-cli/commons-cli
@Test
public void testGetValue()
{
Option option = new Option("f", null);
option.setArgs(Option.UNLIMITED_VALUES);
assertEquals("default", option.getValue("default"));
assertEquals(null, option.getValue(0));
option.addValueForProcessing("foo");
assertEquals("foo", option.getValue());
assertEquals("foo", option.getValue(0));
assertEquals("foo", option.getValue("default"));
}
代码示例来源:origin: apache/nifi
final String optValue = option.getValue() == null ? "" : option.getValue();
properties.setProperty(option.getLongOpt(), optValue);
代码示例来源:origin: embulk/embulk
final OptionDefinition optionDefinitionSpecified =
this.optionDefinitionFromCliOption.get(cliOptionSpecified);
optionDefinitionSpecified.behave(commandLineBuilder, cliOptionSpecified.getValue());
代码示例来源:origin: CalebFenton/simplify
String val = opt.getValue();
switch (opt.getLongOpt()) {
case "output":
代码示例来源:origin: commons-cli/commons-cli
@Test
public void testSubclass()
{
Option option = new DefaultOption("f", "file", "myfile.txt");
Option clone = (Option) option.clone();
assertEquals("myfile.txt", clone.getValue());
assertEquals(DefaultOption.class, clone.getClass());
}
代码示例来源:origin: commons-cli/commons-cli
assertEquals(opt.getValue(0), "JAVA_HOME");
assertEquals(opt.getValue(1), "/opt/java");
break;
case 'p':
assertEquals(opt.getValue(0), "file1");
assertEquals(opt.getValue(1), "file2");
assertEquals(opt.getValue(2), "file3");
break;
default:
代码示例来源:origin: KylinOLAP/Kylin
public String getOptionsAsString() {
StringBuilder buf = new StringBuilder();
for (Option option : commandLine.getOptions()) {
buf.append(" ");
buf.append(option.getOpt());
if (option.hasArg()) {
buf.append("=");
buf.append(option.getValue());
}
}
return buf.toString();
}
代码示例来源:origin: apache/tika
String v = option.getValue();
if (v == null || v.equals("")) {
v = "true";
代码示例来源:origin: org.apache.airavata/airavata-common-utils
protected CommandLineParameters(CommandLine cmd){
for(Option opt:cmd.getOptions()){
parameters.put(revertOption(opt.getOpt()), revertOption(opt.getValue()));
}
for(String arg:cmd.getArgs()){
arguments.add(revertOption(arg));
}
}
public List<String> getArguments() {
代码示例来源:origin: org.apache.kylin/kylin-core-common
public String getOptionsAsString() {
StringBuilder buf = new StringBuilder();
for (Option option : commandLine.getOptions()) {
buf.append(" ");
buf.append(option.getOpt());
if (option.hasArg()) {
buf.append("=");
buf.append(option.getValue());
}
}
return buf.toString();
}
代码示例来源:origin: ch.cern.hadoop/hadoop-mapreduce-client-jobclient
public String toString() {
StringBuilder s = new StringBuilder();
if (parsedData != null) {
Option[] ops = parsedData.getOptions();
for (int i = 0; i < ops.length; ++i) {
s.append(ops[i].getOpt() + " = " + s.append(ops[i].getValue()) + ",");
}
}
return s.toString();
}
内容来源于网络,如有侵权,请联系作者删除!