use of org.apache.commons.cli2.HelpLine in project jackrabbit-filevault by apache.
the class CliHelpFormatter method printHelp.
/**
* Prints detailed help per option.
*/
public void printHelp() {
printDivider();
printDescription();
final Option option;
final PrintWriter out = getPrintWriter();
if ((getException() != null) && (getException().getOption() != null)) {
option = getException().getOption();
} else if (cmd != null) {
option = cmd.getCommand();
} else {
option = getGroup();
}
// grab the HelpLines to display
final List helpLines = option.helpLines(skipToplevel ? -1 : 0, getDisplaySettings(), getComparator());
if (skipToplevel) {
helpLines.remove(0);
}
// calculate the maximum width of the usage strings
int usageWidth = 0;
for (final Iterator i = helpLines.iterator(); i.hasNext(); ) {
final HelpLine helpLine = (HelpLine) i.next();
final String usage = helpLine.usage(getLineUsageSettings(), getComparator());
usageWidth = Math.max(usageWidth, usage.length());
}
// build a blank string to pad wrapped descriptions
final StringBuffer blankBuffer = new StringBuffer();
for (int i = 0; i < usageWidth; i++) {
blankBuffer.append(' ');
}
// print a blank line
out.println();
// determine the width available for descriptions
final int descriptionWidth = Math.max(1, getPageWidth() - getGutterCenter().length() - usageWidth);
// display each HelpLine
for (final Iterator i = helpLines.iterator(); i.hasNext(); ) {
// grab the HelpLine
final HelpLine helpLine = (HelpLine) i.next();
// wrap the description
final List descList = wrap(helpLine.getDescription(), descriptionWidth);
final Iterator descriptionIterator = descList.iterator();
// display usage + first line of description
printGutterLeft();
pad(helpLine.usage(getLineUsageSettings(), getComparator()), usageWidth, out);
out.print(getGutterCenter());
pad((String) descriptionIterator.next(), descriptionWidth, out);
printGutterRight();
out.println();
// display padding + remaining lines of description
while (descriptionIterator.hasNext()) {
printGutterLeft();
// pad(helpLine.getUsage(),usageWidth,out);
out.print(blankBuffer);
out.print(getGutterCenter());
pad((String) descriptionIterator.next(), descriptionWidth, out);
printGutterRight();
out.println();
}
}
printExample();
printDivider();
}
Aggregations