Java Code Examples for org.apache.commons.cli.Option#hasLongOpt()
The following examples show how to use
org.apache.commons.cli.Option#hasLongOpt() .
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: ExhibitorCLI.java From exhibitor with Apache License 2.0 | 6 votes |
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()); } } } }
Example 2
Source File: CLIHelpFormatter.java From kieker with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Override protected StringBuffer renderOptions(final StringBuffer sb, final int width, final Options options, final int leftPad, final int descPad) { final String lpad = this.createPadding(leftPad); final String dpad = this.createPadding(8); // we use a fixed value instead of descPad StringBuilder optBuf; final List<Option> optList = new ArrayList<Option>(options.getOptions()); Collections.sort(optList, this.getOptionComparator()); for (final Iterator<Option> i = optList.iterator(); i.hasNext();) { final Option option = i.next(); optBuf = new StringBuilder(8); if (option.getOpt() == null) { optBuf.append(lpad).append(" ").append(this.getLongOptPrefix()).append(option.getLongOpt()); } else { optBuf.append(lpad).append(this.getOptPrefix()).append(option.getOpt()); if (option.hasLongOpt()) { optBuf.append(',').append(this.getLongOptPrefix()).append(option.getLongOpt()); } } if (option.hasArg()) { if (option.hasArgName()) { optBuf.append(" <").append(option.getArgName()).append('>'); } else { optBuf.append(' '); } } sb.append(optBuf.toString()).append(this.getNewLine()); optBuf = new StringBuilder(); optBuf.append(dpad); if (option.getDescription() != null) { optBuf.append(option.getDescription()); } this.renderWrappedText(sb, width, dpad.length(), optBuf.toString()); if (i.hasNext()) { sb.append(this.getNewLine()); sb.append(this.getNewLine()); } } return sb; }
Example 3
Source File: CommandLineOptions.java From LiquidDonkey with MIT License | 4 votes |
public String opt(Option option) { return option.hasLongOpt() ? option.getLongOpt() : option.getOpt(); }
Example 4
Source File: MarkdownExtensions.java From sarl with Apache License 2.0 | 4 votes |
/** Render the option help to a Markdown table. * * @param options the options. * @return the markdown table. */ protected static String _renderToMarkdown(Options options) { if (options == null) { return ""; //$NON-NLS-1$ } final List<Option> optList = new ArrayList<>(options.getOptions()); if (optList.isEmpty()) { return ""; //$NON-NLS-1$ } Collections.sort(optList, new OptionComparator()); final StringBuilder buffer = new StringBuilder(); for (final Option option : optList) { buffer.append("| `"); //$NON-NLS-1$ if (option.getOpt() == null) { buffer.append(DEFAULT_LONG_OPT_PREFIX).append(option.getLongOpt()); } else { buffer.append(DEFAULT_OPT_PREFIX).append(option.getOpt()); if (option.hasLongOpt()) { buffer.append("`, `"); //$NON-NLS-1$ buffer.append(DEFAULT_LONG_OPT_PREFIX).append(option.getLongOpt()); } } if (option.hasArg()) { if (option.hasArgName()) { buffer.append(" <").append(option.getArgName()).append(">"); //$NON-NLS-1$ //$NON-NLS-2$ } } buffer.append("` | "); //$NON-NLS-1$ if (option.getDescription() != null) { String text = option.getDescription().replaceAll("[ \t\n\r\f]+", " "); //$NON-NLS-1$ //$NON-NLS-2$ text = text.replaceAll("\\<", "<"); //$NON-NLS-1$//$NON-NLS-2$ text = text.replaceAll("\\>", ">"); //$NON-NLS-1$//$NON-NLS-2$ buffer.append(text); } buffer.append(" |\n"); //$NON-NLS-1$ } return buffer.toString(); }