Example usage for org.apache.commons.cli FixedHelpFormatter FixedHelpFormatter

List of usage examples for org.apache.commons.cli FixedHelpFormatter FixedHelpFormatter

Introduction

In this page you can find the example usage for org.apache.commons.cli FixedHelpFormatter FixedHelpFormatter.

Prototype

FixedHelpFormatter

Source Link

Usage

From source file:org.lib4j.cli.Options.java

private static void printHelp(final org.apache.commons.cli.Options apacheOptions,
        final Cli.Arguments cliArguments, final PrintStream ps) {
    final HelpFormatter formatter = new FixedHelpFormatter();
    final PrintWriter pw = new PrintWriter(ps);
    final StringBuilder args = new StringBuilder(apacheOptions.getOptions().size() > 0 ? " [options]" : "");
    if (cliArguments != null) {
        for (short i = 1; i <= cliArguments.getMinOccurs(); i++)
            args.append(" <").append(cliArguments.getLabel()).append(i != 1 ? i : "").append('>');

        final boolean maxUnbounded = "unbounded".equals(cliArguments.getMaxOccurs());
        final int argsMax = maxUnbounded ? 2 + cliArguments.getMinOccurs()
                : Short.parseShort(cliArguments.getMaxOccurs());
        for (int i = cliArguments.getMinOccurs() + 1; i <= argsMax; i++)
            args.append(" [").append(cliArguments.getLabel()).append(i != 1 ? i : "").append(']');

        if (maxUnbounded)
            args.append(" [...]");
    }/*  ww  w .  j  a  v  a  2 s  . c o  m*/

    formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, " ", args.substring(1), apacheOptions,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, false);
    pw.flush();
}

From source file:org.libx4j.cli.Options.java

private static void printHelp(final org.apache.commons.cli.Options apacheOptions,
        final cli_cli._arguments cliArguments, final PrintStream ps) {
    final HelpFormatter formatter = new FixedHelpFormatter();
    final PrintWriter pw = new PrintWriter(ps);
    final StringBuilder args = new StringBuilder(apacheOptions.getOptions().size() > 0 ? " [options]" : "");
    if (cliArguments != null && !cliArguments.isNull()) {
        for (int i = 1; i <= cliArguments._minOccurs$().text(); i++)
            args.append(" <").append(cliArguments._label$().text()).append(i != 1 ? i : "").append(">");

        final boolean maxUnbounded = "unbounded".equals(cliArguments._maxOccurs$().text());
        final int argsMax = maxUnbounded ? 2 + cliArguments._minOccurs$().text()
                : Integer.parseInt(cliArguments._maxOccurs$().text());
        for (int i = cliArguments._minOccurs$().text() + 1; i <= argsMax; i++)
            args.append(" [").append(cliArguments._label$().text()).append(i != 1 ? i : "").append("]");

        if (maxUnbounded)
            args.append(" [...]");
    }/* w  ww  . ja  v  a2 s. co  m*/

    formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, " ", args.substring(1), apacheOptions,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, false);
    pw.flush();
}