本文整理了Java中org.apache.commons.cli.Option.getLongOpt()
方法的一些代码示例,展示了Option.getLongOpt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option.getLongOpt()
方法的具体详情如下:
包路径:org.apache.commons.cli.Option
类名称:Option
方法名:getLongOpt
[英]Retrieve the long name of this Option.
[中]检索此选项的长名称。
代码示例来源:origin: apache/shiro
private static int getRequiredPositiveInt(CommandLine line, Option option) {
String iterVal = line.getOptionValue(option.getOpt());
try {
return Integer.parseInt(iterVal);
} catch (NumberFormatException e) {
String msg = "'" + option.getLongOpt() + "' value must be a positive integer.";
throw new IllegalArgumentException(msg, e);
}
}
代码示例来源:origin: apache/rocketmq
public static Properties commandLine2Properties(final CommandLine commandLine) {
Properties properties = new Properties();
Option[] opts = commandLine.getOptions();
if (opts != null) {
for (Option opt : opts) {
String name = opt.getLongOpt();
String value = commandLine.getOptionValue(name);
if (value != null) {
properties.setProperty(name, value);
}
}
}
return properties;
}
代码示例来源:origin: Alluxio/alluxio
@Override
protected void runPlainPath(AlluxioURI plainPath, CommandLine cl)
throws AlluxioException, IOException {
load(plainPath, cl.hasOption(LOCAL_OPTION.getLongOpt()));
}
代码示例来源:origin: apache/shiro
private static String createMutexMessage(Option... options) {
StringBuilder sb = new StringBuilder();
sb.append("The ");
for (int i = 0; i < options.length; i++) {
if (i > 0) {
sb.append(", ");
}
Option o = options[0];
sb.append("-").append(o.getOpt()).append("/--").append(o.getLongOpt());
}
sb.append(" and generated salt options are mutually exclusive. Only one of them may be used at a time");
return sb.toString();
}
代码示例来源:origin: apache/flink
private static List<URL> checkUrls(CommandLine line, Option option) {
if (line.hasOption(option.getOpt())) {
final String[] urls = line.getOptionValues(option.getOpt());
return Arrays.stream(urls)
.distinct()
.map((url) -> {
try {
return Path.fromLocalFile(new File(url).getAbsoluteFile()).toUri().toURL();
} catch (Exception e) {
throw new SqlClientException("Invalid path for option '" + option.getLongOpt() + "': " + url, e);
}
})
.collect(Collectors.toList());
}
return null;
}
代码示例来源:origin: commons-cli/commons-cli
/**
* Retrieves the array of values, if any, of an option.
*
* @param opt string name of the option
* @return Values of the argument if option is set, and has an argument,
* otherwise null.
*/
public String[] getOptionValues(String opt)
{
List<String> values = new ArrayList<String>();
for (Option option : options)
{
if (opt.equals(option.getOpt()) || opt.equals(option.getLongOpt()))
{
values.addAll(option.getValuesList());
}
}
return values.isEmpty() ? null : values.toArray(new String[values.size()]);
}
代码示例来源:origin: commons-cli/commons-cli
/**
* Retrieves the option object given the long or short option as a String
*
* @param opt short or long name of the option
* @return Canonicalized option
*/
private Option resolveOption(String opt)
{
opt = Util.stripLeadingHyphens(opt);
for (Option option : options)
{
if (opt.equals(option.getOpt()))
{
return option;
}
if (opt.equals(option.getLongOpt()))
{
return option;
}
}
return null;
}
代码示例来源:origin: commons-cli/commons-cli
if (opt.equals(option.getOpt()) || opt.equals(option.getLongOpt()))
代码示例来源:origin: galenframework/galen
public static GalenActionConfigArguments parse(String[] args) {
args = ArgumentsUtils.processSystemProperties(args);
Options options = new Options();
options.addOption("g", "global", false, "Flag to create global config in user home directory");
CommandLineParser parser = new PosixParser();
CommandLine cmd;
try {
cmd = parser.parse(options, args);
} catch (MissingArgumentException e) {
throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
GalenActionConfigArguments configArguments = new GalenActionConfigArguments();
configArguments.isGlobal = cmd.hasOption("g");
return configArguments;
}
代码示例来源:origin: Alluxio/alluxio
@Override
public int run(CommandLine cl) throws IOException {
String[] args = cl.getArgs();
String dir;
if (args.length < 1) {
dir = null;
} else {
dir = args[0];
}
boolean local = cl.hasOption(LOCAL_OPTION.getLongOpt());
BackupResponse resp = mMetaClient.backup(dir, local);
if (local) {
mPrintStream.printf("Successfully backed up journal to %s on master %s%n",
resp.getBackupUri(), resp.getHostname());
} else {
mPrintStream.printf("Successfully backed up journal to %s%n", resp.getBackupUri());
}
return 0;
}
代码示例来源:origin: commons-cli/commons-cli
/**
* Adds an option instance
*
* @param opt the option that is to be added
* @return the resulting Options instance
*/
public Options addOption(Option opt)
{
String key = opt.getKey();
// add it to the long option list
if (opt.hasLongOpt())
{
longOpts.put(opt.getLongOpt(), opt);
}
// if the option is required add it to the required list
if (opt.isRequired())
{
if (requiredOpts.contains(key))
{
requiredOpts.remove(requiredOpts.indexOf(key));
}
requiredOpts.add(key);
}
shortOpts.put(key, opt);
return this;
}
代码示例来源:origin: apache/flink
final String argument = "--" + o.getLongOpt();
代码示例来源:origin: galenframework/galen
public static GalenActionGenerateArguments parse(String[] args) {
args = ArgumentsUtils.processSystemProperties(args);
Options options = new Options();
options.addOption("e", "export", true, "Path to generated spec file");
options.addOption("G", "no-galen-extras", false, "Disable galen-extras expressions");
CommandLineParser parser = new PosixParser();
CommandLine cmd;
try {
cmd = parser.parse(options, args);
} catch (MissingArgumentException e) {
throw new IllegalArgumentException("Missing value for " + e.getOption().getLongOpt(), e);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
GalenActionGenerateArguments arguments = new GalenActionGenerateArguments();
arguments.setExport(cmd.getOptionValue("e"));
arguments.setUseGalenExtras(!cmd.hasOption("G"));
if (cmd.getArgs() == null || cmd.getArgs().length < 1) {
throw new IllegalArgumentException("Missing page dump file");
}
arguments.setPath(cmd.getArgs()[0]);
return arguments;
}
代码示例来源:origin: Alluxio/alluxio
return -1;
if (cl.hasOption(MODE_OPTION.getLongOpt())) {
UfsPMode mode;
switch (cl.getOptionValue(MODE_OPTION.getLongOpt())) {
case "noAccess":
mode = UfsPMode.NO_ACCESS;
代码示例来源:origin: soabase/exhibitor
private void logOptions(String sectionName, String prefix, Options options)
{
if ( sectionName != null )
{
log.info("== " + sectionName + " ==");
}
//noinspection unchecked
for ( Option option : (Iterable<? extends Option>)options.getOptions() )
{
if ( option.hasLongOpt() )
{
if ( option.hasArg() )
{
log.info(prefix + option.getLongOpt() + " <arg> - " + option.getDescription());
}
else
{
log.info(prefix + option.getLongOpt() + " - " + option.getDescription());
}
}
}
}
代码示例来源:origin: Alluxio/alluxio
@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
String[] args = cl.getArgs();
if (args.length == 0) {
Map<String, MountPointInfo> mountTable = mFileSystem.getMountTable();
UfsCommand.printMountInfo(mountTable);
return 0;
}
AlluxioURI alluxioPath = new AlluxioURI(args[0]);
AlluxioURI ufsPath = new AlluxioURI(args[1]);
MountPOptions.Builder optionsBuilder = MountPOptions.newBuilder();
if (cl.hasOption(READONLY_OPTION.getLongOpt())) {
optionsBuilder.setReadOnly(true);
}
if (cl.hasOption(SHARED_OPTION.getLongOpt())) {
optionsBuilder.setShared(true);
}
if (cl.hasOption(OPTION_OPTION.getLongOpt())) {
Properties properties = cl.getOptionProperties(OPTION_OPTION.getLongOpt());
optionsBuilder.putAllProperties(Maps.fromProperties(properties));
}
mFileSystem.mount(alluxioPath, ufsPath, optionsBuilder.build());
System.out.println("Mounted " + ufsPath + " at " + alluxioPath);
return 0;
}
代码示例来源:origin: Alluxio/alluxio
@Override
protected void runPlainPath(AlluxioURI path, CommandLine cl)
throws AlluxioException, IOException {
// TODO(calvin): Remove explicit state checking.
boolean recursive = cl.hasOption("R");
if (!mFileSystem.exists(path)) {
throw new FileDoesNotExistException(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage(path));
}
if (!recursive && mFileSystem.getStatus(path).isFolder()) {
throw new IOException(
path.getPath() + " is a directory, to remove it, please use \"rm -R <path>\"");
}
boolean isAlluxioOnly = cl.hasOption(REMOVE_ALLUXIO_ONLY.getLongOpt());
DeletePOptions options =
DeletePOptions.newBuilder().setRecursive(recursive).setAlluxioOnly(isAlluxioOnly)
.setUnchecked(cl.hasOption(REMOVE_UNCHECKED_OPTION_CHAR)).build();
mFileSystem.delete(path, options);
if (!isAlluxioOnly) {
System.out.println(path + " has been removed");
} else {
System.out.println(path + " has been removed from Alluxio space");
}
}
代码示例来源:origin: commons-cli/commons-cli
@Test
public void testCompleteOption( ) {
Option simple = OptionBuilder.withLongOpt( "simple option")
.hasArg( )
.isRequired( )
.hasArgs( )
.withType( Float.class )
.withDescription( "this is a simple option" )
.create( 's' );
assertEquals( "s", simple.getOpt() );
assertEquals( "simple option", simple.getLongOpt() );
assertEquals( "this is a simple option", simple.getDescription() );
assertEquals( simple.getType(), Float.class );
assertTrue( simple.hasArg() );
assertTrue( simple.isRequired() );
assertTrue( simple.hasArgs() );
}
代码示例来源:origin: commons-cli/commons-cli
@Test
public void testTwoCompleteOptions( ) {
Option simple = OptionBuilder.withLongOpt( "simple option")
.hasArg( )
.isRequired( )
.hasArgs( )
.withType( Float.class )
.withDescription( "this is a simple option" )
.create( 's' );
assertEquals( "s", simple.getOpt() );
assertEquals( "simple option", simple.getLongOpt() );
assertEquals( "this is a simple option", simple.getDescription() );
assertEquals( simple.getType(), Float.class );
assertTrue( simple.hasArg() );
assertTrue( simple.isRequired() );
assertTrue( simple.hasArgs() );
simple = OptionBuilder.withLongOpt( "dimple option")
.hasArg( )
.withDescription( "this is a dimple option" )
.create( 'd' );
assertEquals( "d", simple.getOpt() );
assertEquals( "dimple option", simple.getLongOpt() );
assertEquals( "this is a dimple option", simple.getDescription() );
assertEquals( String.class, simple.getType() );
assertTrue( simple.hasArg() );
assertTrue( !simple.isRequired() );
assertTrue( !simple.hasArgs() );
}
代码示例来源: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());
}
内容来源于网络,如有侵权,请联系作者删除!