/** * Builds the specified text to the specified buffer. * * @param buffer The buffer to write the help to * @param text The text to be written to the buffer */ public void buildWrapped(StringBuilder buffer, String text) { buildWrapped(buffer, 0, text); }
public void computeUsage(StringBuilder buffer, String cmdLineSyntax) { int argPos = cmdLineSyntax.indexOf(' ') + 1; buildWrapped(buffer, getUsagePrefix().length() + argPos, getUsagePrefix() + cmdLineSyntax); }
public void computeUsageLine(StringBuilder buffer, String prefix, CLI cli) { // initialise the string buffer StringBuilder buff; if (prefix == null) { buff = new StringBuilder(getUsagePrefix()); } else { buff = new StringBuilder(getUsagePrefix()).append(prefix); if (!prefix.endsWith(" ")) { buff.append(" "); } } buff.append(cli.getName()).append(" "); if (getOptionComparator() != null) { Collections.sort(cli.getOptions(), getOptionComparator()); } // iterate over the options for (Option option : cli.getOptions()) { appendOption(buff, option); buff.append(" "); } // iterate over the arguments for (Argument arg : cli.getArguments()) { appendArgument(buff, arg, arg.isRequired()); buff.append(" "); } buildWrapped(buffer, buff.toString().indexOf(' ') + 1, buff.toString()); }
/** * Computes the usage of the given {@link CLI}. * * @param builder where the usage is going to be written * @param prefix a prefix to prepend to the usage line. It will be added between 'Usage: ' and the CLI name. * @param cli the cli */ public void usage(StringBuilder builder, String prefix, CLI cli) { computeUsageLine(builder, prefix, cli); if (cli.getSummary() != null && cli.getSummary().trim().length() > 0) { buildWrapped(builder, "\n" + cli.getSummary()); } if (cli.getDescription() != null && cli.getDescription().trim().length() > 0) { buildWrapped(builder, "\n" + cli.getDescription()); } builder.append("\n"); if (cli.getOptions().isEmpty() && cli.getArguments().isEmpty()) { // When we have neither options and arguments, just leave. return; } builder.append("Options and Arguments:\n"); computeOptionsAndArguments(builder, cli.getOptions(), cli.getArguments()); }
/** * Builds the specified text to the specified buffer. * * @param buffer The buffer to write the help to * @param text The text to be written to the buffer */ public void buildWrapped(StringBuilder buffer, String text) { buildWrapped(buffer, 0, text); }
public void computeUsage(StringBuilder buffer, String cmdLineSyntax) { int argPos = cmdLineSyntax.indexOf(' ') + 1; buildWrapped(buffer, getUsagePrefix().length() + argPos, getUsagePrefix() + cmdLineSyntax); }
public void computeUsageLine(StringBuilder buffer, String prefix, CLI cli) { // initialise the string buffer StringBuilder buff; if (prefix == null) { buff = new StringBuilder(getUsagePrefix()); } else { buff = new StringBuilder(getUsagePrefix()).append(prefix); if (!prefix.endsWith(" ")) { buff.append(" "); } } buff.append(cli.getName()).append(" "); if (getOptionComparator() != null) { Collections.sort(cli.getOptions(), getOptionComparator()); } // iterate over the options for (Option option : cli.getOptions()) { appendOption(buff, option); buff.append(" "); } // iterate over the arguments for (Argument arg : cli.getArguments()) { appendArgument(buff, arg, arg.isRequired()); buff.append(" "); } buildWrapped(buffer, buff.toString().indexOf(' ') + 1, buff.toString()); }
/** * Computes the usage of the given {@link CLI}. * * @param builder where the usage is going to be written * @param prefix a prefix to prepend to the usage line. It will be added between 'Usage: ' and the CLI name. * @param cli the cli */ public void usage(StringBuilder builder, String prefix, CLI cli) { computeUsageLine(builder, prefix, cli); if (cli.getSummary() != null && cli.getSummary().trim().length() > 0) { buildWrapped(builder, "\n" + cli.getSummary()); } if (cli.getDescription() != null && cli.getDescription().trim().length() > 0) { buildWrapped(builder, "\n" + cli.getDescription()); } builder.append("\n"); if (cli.getOptions().isEmpty() && cli.getArguments().isEmpty()) { // When we have neither options and arguments, just leave. return; } builder.append("Options and Arguments:\n"); computeOptionsAndArguments(builder, cli.getOptions(), cli.getArguments()); }