org.apache.commons.cli.Option#getLongOpt ( )源码实例Demo

下面列出了org.apache.commons.cli.Option#getLongOpt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: DDMQ   文件: ServerUtil.java
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;
}
 
源代码2 项目: rocketmq-4.3.0   文件: ServerUtil.java
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;
}
 
源代码3 项目: rocketmq-read   文件: ServerUtil.java
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;
}
 
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;
}
 
源代码5 项目: rocketmq   文件: ServerUtil.java
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;
}
 
源代码6 项目: DDMQ   文件: ServerUtil.java
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;
}
 
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;
}
 
源代码8 项目: rug-cli   文件: MkDocs.java
protected static int compareOptions(Option a, Option b) {
    String aShort = a.getOpt();
    String bShort = b.getOpt();
    String aLong = a.getLongOpt();
    String bLong = b.getLongOpt();
    if (aShort != null && aShort.length() > 0 && bShort != null && bShort.length() > 0) {
        return aShort.compareToIgnoreCase(bShort);
    } else if (aLong != null && aLong.length() > 0 && bLong != null && bLong.length() > 0) {
        return aLong.compareToIgnoreCase(bLong);
    } else if (aShort != null && aShort.length() > 0 && bLong != null && bLong.length() > 0) {
        return aShort.compareToIgnoreCase(bLong);
    } else if (aLong != null && aLong.length() > 0 && bShort != null && bShort.length() > 0) {
        return aLong.compareToIgnoreCase(bShort);
    } else {
        return 0;
    }
}
 
源代码9 项目: rocketmq   文件: ServerUtil.java
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;
}
 
源代码10 项目: termsuite-core   文件: CliUtil.java
/**
 * Displays all command line options in log messages.
 * @param line
 */
public static void logCommandLineOptions(Logger logger, CommandLine line) {
	for (Option myOption : line.getOptions()) {
		String message;
		String opt = "";
		if(myOption.getOpt() != null) {
			opt+="-"+myOption.getOpt();
			if(myOption.getLongOpt() != null) 
				opt+=" (--"+myOption.getLongOpt()+")";
		} else
			opt+="--"+myOption.getLongOpt()+"";
			
		if(myOption.hasArg()) 
		    message = opt + " " + myOption.getValue();
		else
			message = opt;
			
		
		logger.info("with option: " + message);
	}
}
 
源代码11 项目: rocketmq   文件: AbstractAction.java
protected void checkOptions(Collection<Option> options) {
    for (Option option : options) {
        if (option.isRequired()) {
            String value = option.getValue();
            if (StringUtils.isBlank(value)) {
                throw new IllegalStateException("option: key =[" + option.getLongOpt() + "], required=["
                        + option.isRequired() + "] is blank!");
            }
        }
    }
}
 
源代码12 项目: rug-cli   文件: MkDocs.java
/**
 * Oh yeah?  It's not as bad as this!
 *
 * @param o  Option to be formatted.
 * @return   Markdown formatted documentation string.
 */
protected static String formatOption(Option o) {
    String shortString = "";
    String shortOpt = o.getOpt();
    if (shortOpt != null && shortOpt.length() > 0) {
        shortString = "-" + shortOpt;
    }
    String longString = "";
    String longOpt = o.getLongOpt();
    if (longOpt != null && longOpt.length() > 0) {
        longString = "--" + longOpt;
    }
    String joinString = "";
    if (shortString.length() > 0 && longString.length() > 0) {
        joinString = ", ";
    }
    String argName = o.getArgName();
    if (argName != null && argName.length() > 0) {
        if (shortString.length() > 0) {
            shortString += " " + argName;
        }
        if (longString.length() > 0) {
            longString += "=" + argName;
        }
    }
    if (shortString.length() > 0) {
        shortString = "`" + shortString + "`";
    }
    if (longString.length() > 0) {
        longString = "`" + longString + "`";
    }
    // This formatting uses the MkDocs def_list markdown extension
    return String.format("%s%s%s\n:   %s\n\n", shortString, joinString, longString, o.getDescription());
}
 
源代码13 项目: incubator-hivemall   文件: OptimizerOptions.java
public static void processOptions(@Nullable CommandLine cl,
        @Nonnull Map<String, String> options) {
    if (cl == null) {
        return;
    }
    for (Option opt : cl.getOptions()) {
        String optName = opt.getLongOpt();
        if (optName == null) {
            optName = opt.getOpt();
        }
        options.put(optName, opt.getValue());
    }
}
 
源代码14 项目: herd   文件: ArgumentParserTest.java
/**
 * Dump state of the Option object instance, suitable for debugging and comparing Options as Strings.
 *
 * @param option the Option object instance to dump the state of
 *
 * @return Stringified form of this Option object instance
 */
private String optionToString(Option option)
{
    StringBuilder buf = new StringBuilder();

    buf.append("[ option: ");
    buf.append(option.getOpt());

    if (option.getLongOpt() != null)
    {
        buf.append(" ").append(option.getLongOpt());
    }

    buf.append(" ");

    if (option.hasArg())
    {
        buf.append(" [ARG]");
    }

    buf.append(" :: ").append(option.getDescription());

    if (option.isRequired())
    {
        buf.append(" [REQUIRED]");
    }

    buf.append(" ]");

    return buf.toString();
}
 
源代码15 项目: sarl   文件: MarkdownExtensions.java
private static String getKey(Option opt) {
	final String val = opt.getLongOpt();
	if (val == null) {
		return opt.getOpt();
	}
	return val;
}
 
源代码16 项目: attic-stratos   文件: CommandCompleter.java
public CommandCompleter(Map<String, Command<StratosCommandContext>> commands) {
    if (logger.isDebugEnabled()) {
        logger.debug("Creating auto complete for {} commands", commands.size());
    }
    fileNameCompleter = new StratosFileNameCompleter();
    argumentMap = new HashMap<String, Collection<String>>();
    defaultCommandCompleter = new StringsCompleter(commands.keySet());
    helpCommandCompleter = new ArgumentCompleter(new StringsCompleter(CliConstants.HELP_ACTION),
            defaultCommandCompleter);
    for (String action : commands.keySet()) {

        Command<StratosCommandContext> command = commands.get(action);
        Options commandOptions = command.getOptions();
        if (commandOptions != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Creating argument completer for command: {}", action);
            }
            List<String> arguments = new ArrayList<String>();
            Collection<?> allOptions = commandOptions.getOptions();
            for (Object o : allOptions) {
                Option option = (Option) o;
                String longOpt = option.getLongOpt();
                String opt = option.getOpt();
                if (StringUtils.isNotBlank(longOpt)) {
                    arguments.add("--" + longOpt);
                } else if (StringUtils.isNotBlank(opt)) {
                    arguments.add("-" + opt);
                }
            }

            argumentMap.put(action, arguments);
        }
    }
}
 
源代码17 项目: datawave   文件: AbstractUIDBuilder.java
@Override
public void configure(final Configuration config, final Option... options) {
    if (null != config) {
        // Get the UID-specific options
        final Map<String,Option> uidOptions;
        if (null != options) {
            uidOptions = new HashMap<>(4);
            for (final Option option : options) {
                if (null != option) {
                    // Look for one of the 4 types of UID options
                    final String key = option.getLongOpt();
                    final String value;
                    if (UIDConstants.UID_TYPE_OPT.equals(key)) {
                        value = option.getValue(HashUID.class.getSimpleName());
                    } else if (UIDConstants.HOST_INDEX_OPT.equals(key)) {
                        value = option.getValue();
                    } else if (UIDConstants.PROCESS_INDEX_OPT.equals(key)) {
                        value = option.getValue();
                    } else if (UIDConstants.THREAD_INDEX_OPT.equals(key)) {
                        value = option.getValue();
                    } else {
                        value = null;
                    }
                    
                    // Check for null
                    if (null != value) {
                        // Put the key and value into the map
                        uidOptions.put(key, option);
                        
                        // Stop looping if we've got everything we need
                        if (uidOptions.size() >= 4) {
                            break;
                        } else if (UIDConstants.UID_TYPE_OPT.equals(key) && HashUID.class.getSimpleName().equals(value)) {
                            break;
                        }
                    }
                }
            }
        } else {
            uidOptions = Collections.emptyMap();
        }
        
        // Configure with the UID-specific options
        configure(config, uidOptions);
    }
}
 
源代码18 项目: LiquidDonkey   文件: CommandLineOptions.java
public String opt(Option option) {
    return option.hasLongOpt()
            ? option.getLongOpt()
            : option.getOpt();
}
 
源代码19 项目: phoenix   文件: IndexScrutinyTool.java
private void requireOption(CommandLine cmdLine, Option option) {
    if (!cmdLine.hasOption(option.getOpt())) {
        throw new IllegalStateException(option.getLongOpt() + " is a mandatory parameter");
    }
}