use of com.unboundid.util.ExampleCommandLineArgument in project ldapsdk by pingidentity.
the class GenerateToolUsage method writeExamples.
/**
* Writes the example usages for the provided tool or subcommand to the
* given writer.
*
* @param w The writer to use to write the example usages. It must not be
* {@code null}.
* @param t The name of the tool. It must not be {@code null}.
* @param s The name of the subcommand. It may be {@code null} if the
* examples are not for a specific subcommand.
* @param m The map of example usages.
*/
private static void writeExamples(final PrintWriter w, final String t, final String s, final LinkedHashMap<String[], String> m) {
if ((m == null) || m.isEmpty()) {
return;
}
w.println("Examples");
for (final Map.Entry<String[], String> e : m.entrySet()) {
final String[] args = e.getKey();
final String description = e.getValue();
w.println();
for (final String line : StaticUtils.wrapLine(description, 77)) {
w.println(" " + line);
}
w.println();
final StringBuilder buffer = new StringBuilder();
buffer.append(" ");
buffer.append(t);
if (s != null) {
buffer.append(' ');
buffer.append(s);
}
for (int i = 0; i < args.length; i++) {
buffer.append(' ');
// If the argument has a value, then make sure to keep it on the same
// line as the argument name. This may introduce false positives due to
// unnamed trailing arguments, but the worst that will happen that case
// is that the output may be wrapped earlier than necessary one time.
String arg = args[i];
if (arg.startsWith("-")) {
if ((i < (args.length - 1)) && (!args[i + 1].startsWith("-"))) {
final ExampleCommandLineArgument cleanArg = ExampleCommandLineArgument.getCleanArgument(args[i + 1]);
arg += ' ' + cleanArg.getLocalForm();
i++;
}
} else {
final ExampleCommandLineArgument cleanArg = ExampleCommandLineArgument.getCleanArgument(arg);
arg = cleanArg.getLocalForm();
}
if ((buffer.length() + arg.length() + 2) < 79) {
buffer.append(arg);
} else {
buffer.append('\\');
w.println(buffer.toString());
buffer.setLength(0);
buffer.append(" ");
buffer.append(arg);
}
}
w.println(buffer.toString());
}
}
use of com.unboundid.util.ExampleCommandLineArgument in project ldapsdk by pingidentity.
the class GenerateToolUsage method printHTMLExamples.
/**
* Writes HTML-formatted example usages for the provided tool or subcommand
* to the given writer.
*
* @param w The writer to use to write the example usages. It must not be
* {@code null}.
* @param t The name of the tool. It must not be {@code null}.
* @param s The name of the subcommand. It may be {@code null} if the
* examples are not for a specific subcommand.
* @param m The map of example usages.
*/
private void printHTMLExamples(final PrintWriter w, final String t, final String s, final LinkedHashMap<String[], String> m) {
if ((m == null) || m.isEmpty()) {
return;
}
w.println(" <h3>Examples</h3>");
for (final Map.Entry<String[], String> e : m.entrySet()) {
w.println(" <ul>");
w.println(" <li>" + htmlEscape(e.getValue()) + "</li>");
w.println(" </ul>");
w.print(" <blockquote><pre>");
final StringBuilder buffer = new StringBuilder();
buffer.append(" ");
buffer.append(t);
if (s != null) {
buffer.append(' ');
buffer.append(s);
}
final String[] args = e.getKey();
for (int i = 0; i < args.length; i++) {
buffer.append(' ');
// If the argument has a value, then make sure to keep it on the same
// line as the argument name. This may introduce false positives due to
// unnamed trailing arguments, but the worst that will happen that case
// is that the output may be wrapped earlier than necessary one time.
String arg = args[i];
if (arg.startsWith("-")) {
if ((i < (args.length - 1)) && (!args[i + 1].startsWith("-"))) {
final ExampleCommandLineArgument cleanArg = ExampleCommandLineArgument.getCleanArgument(args[i + 1]);
arg += ' ' + cleanArg.getLocalForm();
i++;
}
} else {
final ExampleCommandLineArgument cleanArg = ExampleCommandLineArgument.getCleanArgument(arg);
arg = cleanArg.getLocalForm();
}
if ((buffer.length() + arg.length() + 2) < 79) {
buffer.append(arg);
} else {
buffer.append('\\');
w.println(buffer.toString());
buffer.setLength(0);
buffer.append(" ");
buffer.append(arg);
}
}
w.println(buffer.toString() + "</pre></blockquote>");
}
}
Aggregations