List of usage examples for org.apache.commons.cli Option hasArgName
public boolean hasArgName()
From source file:kieker.tools.util.CLIHelpFormatter.java
@SuppressWarnings("unchecked") @Override//w w w .j a va2 s. c o m 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; }
From source file:net.sf.clichart.main.FixedHelpFormatter.java
protected StringBuffer renderOptions(StringBuffer sb, int width, Options options, int leftPad, int descPad) { final String lpad = createPadding(leftPad); final String dpad = createPadding(descPad); //first create list containing only <lpad>-a,--aaa where -a is opt and --aaa is //long opt; in parallel look for the longest opt string //this list will be then used to sort options ascending int max = 0;/*from w w w . j av a 2 s. c om*/ StringBuffer optBuf; List prefixList = new ArrayList(); Option option; //List optList = options.helpOptions(); Collection optionsCollection = options.getOptions(); List optList = new ArrayList(optionsCollection); Collections.sort(optList, new StringBufferComparator()); for (Iterator i = optList.iterator(); i.hasNext();) { option = (Option) i.next(); optBuf = new StringBuffer(8); if (option.getOpt().equals(" ")) { optBuf.append(lpad).append(" " + defaultLongOptPrefix).append(option.getLongOpt()); } else { optBuf.append(lpad).append(defaultOptPrefix).append(option.getOpt()); if (option.hasLongOpt()) { optBuf.append(',').append(defaultLongOptPrefix).append(option.getLongOpt()); } } if (option.hasArg()) { if (option.hasArgName()) { optBuf.append(" <").append(option.getArgName()).append('>'); } else { optBuf.append(' '); } } prefixList.add(optBuf); max = optBuf.length() > max ? optBuf.length() : max; } int x = 0; for (Iterator i = optList.iterator(); i.hasNext();) { option = (Option) i.next(); optBuf = new StringBuffer(prefixList.get(x++).toString()); if (optBuf.length() < max) { optBuf.append(createPadding(max - optBuf.length())); } optBuf.append(dpad); int nextLineTabStop = max + descPad; renderWrappedText(sb, width, nextLineTabStop, optBuf.append(option.getDescription()).toString()); if (i.hasNext()) { sb.append(defaultNewLine); } } return sb; }
From source file:org.apache.geronimo.cli.PrintHelper.java
protected StringBuilder renderOptions(StringBuilder sb, int width, Options options, int leftPad, int descPad, boolean displayDesc) { final String lpad = createPadding(leftPad); final String dpad = createPadding(descPad); //first create list containing only <lpad>-a,--aaa where -a is opt and --aaa is //long opt; in parallel look for the longest opt string //this list will be then used to sort options ascending int max = 0;/* www . j a v a 2s . c o m*/ StringBuilder optBuf; List prefixList = new ArrayList(); Option option; List optList = new ArrayList(options.getOptions()); Collections.sort(optList, new StringBuilderComparator()); for (Iterator i = optList.iterator(); i.hasNext();) { option = (Option) i.next(); optBuf = new StringBuilder(8); if (option.getOpt().equals(" ")) { optBuf.append(lpad).append(" " + defaultLongOptPrefix).append(option.getLongOpt()); } else { optBuf.append(lpad).append(defaultOptPrefix).append(option.getOpt()); if (option.hasLongOpt()) { optBuf.append(',').append(defaultLongOptPrefix).append(option.getLongOpt()); } } if (option.hasArg()) { if (option.hasArgName()) { optBuf.append(" <").append(option.getArgName()).append('>'); } else { optBuf.append(' '); } } prefixList.add(optBuf); max = optBuf.length() > max ? optBuf.length() : max; } int x = 0; for (Iterator i = optList.iterator(); i.hasNext();) { option = (Option) i.next(); optBuf = new StringBuilder(prefixList.get(x++).toString()); if (optBuf.length() < max) { optBuf.append(createPadding(max - optBuf.length())); } optBuf.append(dpad); if (displayDesc) { optBuf.append(option.getDescription()); } int nextLineTabStop = max + descPad; renderWrappedText(sb, width, nextLineTabStop, optBuf.toString()); if (i.hasNext()) { sb.append(defaultNewLine); if (displayDesc) { sb.append(defaultNewLine); } } } return sb; }
From source file:org.apache.maven.cli.CLIManagerDocumentationTest.java
public String getOptionsAsHtml() { StringBuilder sb = new StringBuilder(512); boolean a = true; sb.append(//from w w w.j a va 2 s. c om "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>"); for (Option option : new CLIManagerExtension().getOptions()) { a = !a; sb.append("<tr class='").append(a ? 'a' : 'b').append("'><td><code>-<a name='"); sb.append(option.getOpt()); sb.append("'>"); sb.append(option.getOpt()); sb.append("</a>,--<a name='"); sb.append(option.getLongOpt()); sb.append("'>"); sb.append(option.getLongOpt()); sb.append("</a>"); if (option.hasArg()) { if (option.hasArgName()) { sb.append(" <").append(option.getArgName()).append(">"); } else { sb.append(' '); } } sb.append("</code></td><td>"); sb.append(option.getDescription()); sb.append("</td></tr>"); sb.append(LS); } sb.append("</table>"); return sb.toString(); }
From source file:org.apache.maven.cli.CLIManagerTest.java
public String getOptionsAsHtml() { StringBuilder sb = new StringBuilder(); boolean a = true; sb.append(/*from ww w . j a v a 2 s.c o m*/ "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>"); for (Option option : new CLIManagerExtension().getOptions()) { a = !a; sb.append("<tr class='").append(a ? 'a' : 'b').append("'><td><code>-<a name='"); sb.append(option.getOpt()); sb.append("'>"); sb.append(option.getOpt()); sb.append("</a>,--<a name='"); sb.append(option.getLongOpt()); sb.append("'>"); sb.append(option.getLongOpt()); sb.append("</a>"); if (option.hasArg()) { if (option.hasArgName()) { sb.append(" <").append(option.getArgName()).append(">"); } else { sb.append(' '); } } sb.append("</code></td><td>"); sb.append(option.getDescription()); sb.append("</td></tr>"); sb.append(LS); } sb.append("</table>"); return sb.toString(); }
From source file:org.apache.maven.index.cli.NexusIndexerCliTest.java
public String getOptionsAsHtml() { @SuppressWarnings("unchecked") List<Option> optList = new ArrayList<Option>(new NexusIndexerCli().buildDefaultCliOptions().getOptions()); Collections.sort(optList, new OptionComparator()); StringBuilder sb = new StringBuilder(); boolean a = true; sb.append(/*from w w w.java 2s .c om*/ "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>"); for (Option option : optList) { a = !a; sb.append("<tr class='").append(a ? 'a' : 'b').append("'><td><code>-<a name='"); sb.append(option.getOpt()); sb.append("'>"); sb.append(option.getOpt()); sb.append("</a>,--<a name='"); sb.append(option.getLongOpt()); sb.append("'>"); sb.append(option.getLongOpt()); sb.append("</a>"); if (option.hasArg()) { if (option.hasArgName()) { sb.append(" <").append(option.getArgName()).append(">"); } else { sb.append(' '); } } sb.append("</code></td><td>"); sb.append(option.getDescription()); sb.append("</td></tr>"); sb.append(LS); } sb.append("</table>"); return sb.toString(); }
From source file:org.opentestsystem.airose.optionCli.ArgOptions.java
public void parseOptions(String[] commandLine) { for (int i = 0; i < commandLine.length; ++i) { String s = commandLine[i]; if (s.startsWith("--")) { // see if the option is combined with a value int index = s.indexOf("="); if (index > 0) { String optionName = s.substring(2, index); String value = s.substring(index + 1); if (value.length() == 0) { throw new Error("no value specified for " + optionName); }/* w w w . j a v a2 s .c o m*/ Option o = _options.getOption(optionName); if (o == null) { throw new IllegalArgumentException("unrecognizedOption: " + s); } if (o.hasArgName()) { throw new Error("Option " + optionName + " does not " + "take a value"); } this._optionToValue.put(optionToString(o), value); } // the option was not combined with a value, but may still // require one, so load the Option and then decide else { String optionName = s.substring(2); Option o = _options.getOption(optionName); if (o == null) { throw new IllegalArgumentException("unrecognizedOption: " + s); } if (o.hasArgName()) { // because the value combined case was handled above, // the value must be in the next command line argument // position if (i + 1 >= commandLine.length) { throw new Error("no value specified for " + optionName); } else { String value = commandLine[++i]; _optionToValue.put(optionToString(o), value); } } // no value was required for this option. else { _optionToValue.put(optionToString(o), null); } } } // Single character options are more complex as they require // handling multiple single character options per string as well as // having the value specified as a part of the option string with no // intervening '=' character. else if (s.startsWith("-")) { for (int j = 1; j < s.length(); ++j) { char optionName = s.charAt(j); Option o = _options.getOption(Character.toString(optionName)); if (o == null) { throw new IllegalArgumentException("unrecognizedOption: " + s); } // hasValue() if (o.hasArgName()) { // see if there are remaining characters as a part of // this string and if so, use them as the value, // e.g. -xtrue if (j + 1 < s.length()) { String value = s.substring(j + 1); _optionToValue.put(optionToString(o), value); } // otherwise, the next argument in command line is the // value for this option else { // check to ensure that there is at least one more // value if (i + 1 == commandLine.length) { throw new Error("no value specified for " + o); } String value = commandLine[++i]; _optionToValue.put(optionToString(o), value); } break; } else { _optionToValue.put(optionToString(o), null); } } } } }