Example usage for org.apache.commons.cli HelpFormatter getWidth

List of usage examples for org.apache.commons.cli HelpFormatter getWidth

Introduction

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

Prototype

public int getWidth() 

Source Link

Document

Returns the 'width'.

Usage

From source file:com.emc.ecs.sync.cli.CliHelper.java

public static String longHelp() {
    StringWriter helpWriter = new StringWriter();
    PrintWriter pw = new PrintWriter(helpWriter);
    HelpFormatter fmt = new HelpFormatter();
    fmt.setWidth(79);/*from w w w. j  av a2 s. c  om*/

    // main CLI options
    Options options = ConfigUtil.wrapperFor(CliConfig.class).getOptions();

    // sync options
    for (Option o : ConfigUtil.wrapperFor(SyncOptions.class).getOptions().getOptions()) {
        options.addOption(o);
    }

    // Make sure we do CommonOptions first
    String usage = "java -jar ecs-sync.jar -source <source-uri> [-filters <filter1>[,<filter2>,...]] -target <target-uri> [options]";
    fmt.printHelp(pw, fmt.getWidth(), usage, "Common options:", options, fmt.getLeftPadding(),
            fmt.getDescPadding(), null);

    pw.print("\nAvailable plugins are listed below along with any custom options they may have\n");

    // Do the rest
    for (ConfigWrapper<?> storageWrapper : ConfigUtil.allStorageConfigWrappers()) {
        pw.write('\n');
        pw.write(String.format("%s (%s)\n", storageWrapper.getLabel(), storageWrapper.getUriPrefix()));
        fmt.printWrapped(pw, fmt.getWidth(), 4, "    " + storageWrapper.getDocumentation());
        fmt.printWrapped(pw, fmt.getWidth(), 4,
                "    NOTE: Storage options must be prefixed by source- or target-, depending on which role they assume");
        fmt.printOptions(pw, fmt.getWidth(), storageWrapper.getOptions(), fmt.getLeftPadding(),
                fmt.getDescPadding());
    }
    for (ConfigWrapper<?> filterWrapper : ConfigUtil.allFilterConfigWrappers()) {
        pw.write('\n');
        pw.write(String.format("%s (%s)\n", filterWrapper.getLabel(), filterWrapper.getCliName()));
        fmt.printWrapped(pw, fmt.getWidth(), 4, "    " + filterWrapper.getDocumentation());
        fmt.printOptions(pw, fmt.getWidth(), filterWrapper.getOptions(), fmt.getLeftPadding(),
                fmt.getDescPadding());
    }

    return helpWriter.toString();
}

From source file:ai.grakn.graql.GraqlShell.java

private static void printUsage(Options options, String footer) {
    HelpFormatter helpFormatter = new HelpFormatter();
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(System.out, Charset.defaultCharset());
    PrintWriter printWriter = new PrintWriter(new BufferedWriter(outputStreamWriter));
    int width = helpFormatter.getWidth();
    int leftPadding = helpFormatter.getLeftPadding();
    int descPadding = helpFormatter.getDescPadding();
    helpFormatter.printHelp(printWriter, width, "graql.sh", null, options, leftPadding, descPadding, footer);
    printWriter.flush();/*from w  w w .  j av a2  s . c  om*/
}

From source file:com.msbmsb.genealogeo.ui.cli.GenealoGeoCLI.java

/**
 * Display usage message//from  www.j a  v a2  s. c  om
 */
public void usage(String msg) {
    HelpFormatter hf = new HelpFormatter();
    PrintWriter pw = new PrintWriter(System.err);
    hf.setSyntaxPrefix("Usage: ");
    hf.printHelp(pw, hf.getWidth(), this.usage, null, this.opts, hf.getLeftPadding(), hf.getDescPadding(), msg,
            false);
    pw.flush();
    System.exit(1);
}

From source file:com.zimbra.common.calendar.ZoneInfo2iCalendar.java

private static void usage(String errmsg) {
    if (errmsg != null) {
        System.err.println(errmsg);
    }/*from   w  w  w  .j  a  v a 2 s .c  o m*/

    String usage = "zmtzdata2ical <options> [tzdata source files ...]";
    Options opts = sOptions;
    PrintWriter pw = new PrintWriter(System.err, true);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, formatter.getWidth(), usage, null, opts, formatter.getLeftPadding(),
            formatter.getDescPadding(), null);
    pw.flush();
}

From source file:net.freifunk.autodeploy.ui.commandline.CommandLineParserImpl.java

@Override
public String getHelpText() {
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    final PrintWriter writer = new PrintWriter(outputStream);

    final HelpFormatter helpFormatter = new HelpFormatter();
    helpFormatter.printHelp(writer, helpFormatter.getWidth(), "ff-autodeploy", null, // no header
            createOptions(), helpFormatter.getLeftPadding(), helpFormatter.getDescPadding(), null, // no footer
            false // no auto usage
    );/*from  w w w. ja  v  a2  s .co  m*/

    writer.flush();
    return new String(outputStream.toByteArray());
}

From source file:grakn.core.console.GraknConsole.java

private void printHelp(PrintStream sout) {
    HelpFormatter formatter = new HelpFormatter();
    OutputStreamWriter writer = new OutputStreamWriter(sout, Charset.defaultCharset());
    PrintWriter printer = new PrintWriter(new BufferedWriter(writer));
    formatter.printHelp(printer, formatter.getWidth(), "grakn console [options]", null, options,
            formatter.getLeftPadding(), formatter.getDescPadding(), null);
    printer.flush();//from   w w w .  jav  a 2  s.  co m
}

From source file:com.zimbra.cs.db.JdbcClient.java

private void usage(ParseException e) {
    if (e != null) {
        System.err.println(e + "\n");
    }//from   ww  w  .  j a v a2  s  .co m

    PrintWriter pw = new PrintWriter(System.err, true);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, formatter.getWidth(), "zmsql <options>", null, mOptions, formatter.getLeftPadding(),
            formatter.getDescPadding(), "");

}

From source file:ai.grakn.migration.base.io.MigrationCLI.java

private void printHelpMessage() {
    HelpFormatter helpFormatter = new HelpFormatter();
    PrintWriter printWriter = new PrintWriter(System.out);
    int width = helpFormatter.getWidth();
    int leftPadding = helpFormatter.getLeftPadding();
    int descPadding = helpFormatter.getDescPadding();
    helpFormatter.printHelp(printWriter, width, "migration.sh", null, defaultOptions, leftPadding, descPadding,
            null);//from w w  w . ja va 2  s  .  c o m
    printWriter.flush();
}

From source file:com.facebook.stetho.dumpapp.Dumper.java

private void dumpUsage(PrintStream output) {
    final String cmdName = "dumpapp";
    HelpFormatter formatter = new HelpFormatter();

    output.println("Usage: " + cmdName + " [options] <plugin> [plugin-options]");

    PrintWriter writer = new PrintWriter(output);
    try {/*from  w ww  . j  a  v  a 2 s .  c o  m*/
        formatter.printOptions(writer, formatter.getWidth(), mGlobalOptions.options, formatter.getLeftPadding(),
                formatter.getDescPadding());
    } finally {
        writer.flush();
    }
}

From source file:com.cloudera.sqoop.cli.ToolOptions.java

/**
 * Print the help to the specified PrintWriter, using the specified
 * help formatter./*from   w  ww.  j  ava2s. com*/
 * @param formatter the HelpFormatter to use.
 * @param pw the PrintWriter to emit to.
 */
public void printHelp(HelpFormatter formatter, PrintWriter pw) {
    boolean first = true;
    for (RelatedOptions optGroup : optGroups) {
        if (!first) {
            pw.println("");
        }
        pw.println(optGroup.getTitle() + ":");
        formatter.printOptions(pw, formatter.getWidth(), optGroup, 0, 4);
        first = false;
    }
}