Java Code Examples for org.apache.commons.cli.Option#getLongOpt()
The following examples show how to use
org.apache.commons.cli.Option#getLongOpt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServerUtil.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
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; }
Example 2
Source File: CliUtil.java From termsuite-core with Apache License 2.0 | 6 votes |
/** * 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); } }
Example 3
Source File: ServerUtil.java From rocketmq with Apache License 2.0 | 6 votes |
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; }
Example 4
Source File: MkDocs.java From rug-cli with GNU General Public License v3.0 | 6 votes |
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; } }
Example 5
Source File: ServerUtil.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
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; }
Example 6
Source File: ServerUtil.java From DDMQ with Apache License 2.0 | 6 votes |
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; }
Example 7
Source File: ServerUtil.java From rocketmq with Apache License 2.0 | 6 votes |
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; }
Example 8
Source File: ServerUtil.java From openmessaging-connect-runtime with Apache License 2.0 | 6 votes |
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; }
Example 9
Source File: ServerUtil.java From rocketmq-read with Apache License 2.0 | 6 votes |
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; }
Example 10
Source File: ServerUtil.java From DDMQ with Apache License 2.0 | 6 votes |
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; }
Example 11
Source File: AbstractAction.java From rocketmq with Apache License 2.0 | 5 votes |
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!"); } } } }
Example 12
Source File: MkDocs.java From rug-cli with GNU General Public License v3.0 | 5 votes |
/** * 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()); }
Example 13
Source File: OptimizerOptions.java From incubator-hivemall with Apache License 2.0 | 5 votes |
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()); } }
Example 14
Source File: ArgumentParserTest.java From herd with Apache License 2.0 | 5 votes |
/** * 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(); }
Example 15
Source File: MarkdownExtensions.java From sarl with Apache License 2.0 | 5 votes |
private static String getKey(Option opt) { final String val = opt.getLongOpt(); if (val == null) { return opt.getOpt(); } return val; }
Example 16
Source File: CommandCompleter.java From attic-stratos with Apache License 2.0 | 5 votes |
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); } } }
Example 17
Source File: AbstractUIDBuilder.java From datawave with Apache License 2.0 | 4 votes |
@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); } }
Example 18
Source File: CommandLineOptions.java From LiquidDonkey with MIT License | 4 votes |
public String opt(Option option) { return option.hasLongOpt() ? option.getLongOpt() : option.getOpt(); }
Example 19
Source File: IndexScrutinyTool.java From phoenix with Apache License 2.0 | 4 votes |
private void requireOption(CommandLine cmdLine, Option option) { if (!cmdLine.hasOption(option.getOpt())) { throw new IllegalStateException(option.getLongOpt() + " is a mandatory parameter"); } }