本文整理了Java中org.apache.commons.cli.Option.getArgName()
方法的一些代码示例,展示了Option.getArgName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.getArgName()
方法的具体详情如下:
包路径:org.apache.commons.cli.Option
类名称:Option
方法名:getArgName
[英]Gets the display name for the argument value.
[中]获取参数值的显示名称。
代码示例来源:origin: commons-cli/commons-cli
if (option.hasArg() && (option.getArgName() == null || option.getArgName().length() != 0))
buff.append("<").append(option.getArgName() != null ? option.getArgName() : getArgName()).append(">");
代码示例来源:origin: apache/kylin
@Override
protected void execute(OptionsHelper optionsHelper) throws Exception {
kylinConfig = KylinConfig.getInstanceFromEnv();
if (optionsHelper.hasOption(OPTION_FORCE_INGEST)) {
forceIngest = Boolean.parseBoolean(optionsHelper.getOptionValue(OPTION_FORCE_INGEST));
}
if (optionsHelper.hasOption(OPTION_OVERWRITE_TABLES)) {
overwriteTables = Boolean.parseBoolean(optionsHelper.getOptionValue(OPTION_OVERWRITE_TABLES));
}
targetProjectName = optionsHelper.getOptionValue(OPTION_PROJECT);
String srcPath = optionsHelper.getOptionValue(OPTION_SRC);
if (!srcPath.endsWith(".zip")) {
throw new IllegalArgumentException(OPTION_SRC.getArgName() + " has to be a zip file");
}
File zipFile = new File(srcPath);
if (zipFile.isDirectory() || !zipFile.exists()) {
throw new IllegalArgumentException(OPTION_SRC.getArgName() + " file does does exist");
}
Path tempPath = Files.createTempDirectory("_unzip");
File tempFolder = tempPath.toFile();
tempFolder.deleteOnExit();
ZipFileUtils.decompressZipfileToDirectory(srcPath, tempFolder);
if (tempFolder.list().length != 1) {
throw new IllegalStateException(Arrays.toString(tempFolder.list()));
}
injest(tempFolder.listFiles()[0].getAbsoluteFile());
}
代码示例来源:origin: commons-cli/commons-cli
String argName = option.getArgName();
if (argName != null && argName.length() == 0)
optBuf.append("<").append(argName != null ? option.getArgName() : getArgName()).append(">");
代码示例来源:origin: embulk/embulk
final String argName = option.getArgName();
if (argName != null && argName.length() == 0) {
optionLinePrefixBuilder.append(' ');
} else {
optionLinePrefixBuilder.append(option.hasLongOpt() ? getLongOptSeparator() : " ");
optionLinePrefixBuilder.append(argName != null ? option.getArgName() : getArgName());
代码示例来源: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: edu.stanford.protege/org.protege.owl.server
private String getOptionValue(CommandLine cmd, Option option) {
String value = cmd.getOptionValue(option.getArgName());
if (value == null) {
value = cmd.getOptionValue(option.getLongOpt());
}
return value;
}
代码示例来源:origin: edu.stanford.protege/org.protege.owl.server
protected void loadCommandLine(CommandLine cmd) {
needsHelp = cmd.hasOption(NEEDS_HELP_OPTION.getArgName()) || cmd.hasOption(NEEDS_HELP_OPTION.getLongOpt());
}
代码示例来源: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.hadoop/hadoop-yarn-client
public boolean getHelp(String cmd, StringBuilder strcnd, boolean addDesc) {
Option opt = options.getOption(cmd);
if (opt != null) {
strcnd.append(DEFAULT_SEPARATOR).append(" -").append(opt.getOpt());
if (opt.hasArg()) {
strcnd.append(" <").append(opt.getArgName()).append(">");
}
if (addDesc) {
strcnd.append(DEFAULT_SEPARATOR).append("\t")
.append(opt.getDescription());
}
}
return opt == null;
}
代码示例来源:origin: geomesa/geomesa-tutorials
public static Map<String, String> getDataStoreParams(CommandLine command, Options options) {
Map<String, String> params = new HashMap<>();
// noinspection unchecked
for (Option opt: options.getOptions()) {
String value = command.getOptionValue(opt.getLongOpt());
if (value != null) {
params.put(opt.getArgName(), value);
}
}
return params;
}
}
代码示例来源: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: eu.fbk.twm/twm-wiki
public static void writeLog(ExtractorParameters extractorParameters, CommandLine commandLine, String[] args, String fileName) throws IOException {
logger.debug("writing log (" + fileName + ")...");
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8")));
pw.println("date='" + new Date() + "'");
pw.print("command='java -cp dist/thewikimachine.jar eu.fbk.twm.wiki.ModelExtractor");
for (int i = 0; i < args.length; i++) {
pw.print(" ");
pw.print(args[i]);
}
pw.print("'\n");
pw.println(extractorParameters);
Iterator<Option> it = commandLine.iterator();
for (int i = 0; it.hasNext(); i++) {
Option opt = it.next();
pw.println(opt.getArgName() + "='" + opt.getValue() + "'");
}
pw.close();
}
代码示例来源: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: org.rundeck/rundeck-core
/**
* Return a string to display the specified option in help text
* @param extended if true, include full argument descriptor
* @param opt opt name
* @return display string
*/
protected String optionDisplayString(final String opt, boolean extended) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("-").append(opt);
Option option = getOption(opt);
if(null!=option) {
if (option.getLongOpt() != null) {
stringBuffer.append("/--");
stringBuffer.append(option.getLongOpt());
}
if(option.getArgName()!=null && extended){
stringBuffer.append(" <");
stringBuffer.append(option.getArgName());
stringBuffer.append(">");
}
}
return stringBuffer.toString();
}
代码示例来源:origin: org.apache.rya/rya.export.client
/**
* Gets and parses the time from the configuration or command line.
* This is for API and is not used internally as of v3.2.11
* @return a time or throws an exception when no time is configured because time is required.
* @throws MergeConfigurationException when date is badly formated or missing.
*/
public Date getRyaStatementMergeTime() throws MergeConfigurationException {
final Date time;
if(cmd.hasOption(TIME_OPTION.getOpt())) {
final String dateStr = cmd.getOptionValue(TIME_OPTION.getOpt());
try {
time = DATE_FORMAT.parse(dateStr);
} catch (final java.text.ParseException e) {
throw new MergeConfigurationException("The provided timestamp was not formatted correctly.", e);
}
} else {
throw new MergeConfigurationException("The "+TIME_OPTION.getArgName()+" option was not specified. "+TIME_OPTION.getDescription());
}
return time;
}
代码示例来源:origin: apache/incubator-rya
/**
* Gets and parses the time from the configuration or command line.
* This is for API and is not used internally as of v3.2.11
* @return a time or throws an exception when no time is configured because time is required.
* @throws MergeConfigurationException when date is badly formated or missing.
*/
public Date getRyaStatementMergeTime() throws MergeConfigurationException {
final Date time;
if(cmd.hasOption(TIME_OPTION.getOpt())) {
final String dateStr = cmd.getOptionValue(TIME_OPTION.getOpt());
try {
time = DATE_FORMAT.parse(dateStr);
} catch (final java.text.ParseException e) {
throw new MergeConfigurationException("The provided timestamp was not formatted correctly.", e);
}
} else {
throw new MergeConfigurationException("The "+TIME_OPTION.getArgName()+" option was not specified. "+TIME_OPTION.getDescription());
}
return time;
}
代码示例来源:origin: net.krotscheck/kangaroo-common
/**
* Add commandline options. This path will exit if the options are not
*
* @param args Commandline argument list.
* @return This builder.
*/
public ConfigurationBuilder addCommandlineArgs(final String[] args) {
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(commandlineOptions, args, false);
} catch (ParseException e) {
HelpFormatter formater = new HelpFormatter();
formater.setWidth(120);
formater.printHelp("Main", commandlineOptions);
throw new RuntimeException();
}
Map<String, String> cliProps = new HashMap<>();
for (Option o : cmd.getOptions()) {
cliProps.put(o.getArgName(), o.getValue());
}
cliConfiguration = new MapConfiguration(cliProps);
return this;
}
代码示例来源: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());
}
内容来源于网络,如有侵权,请联系作者删除!