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:io.github.azige.mages.Cli.java

static void printHelp(PrintStream out, Options options) {
    HelpFormatter hf = new HelpFormatter();
    PrintWriter pw = new PrintWriter(out);
    hf.printHelp(pw, hf.getWidth(),
            "mages [-r <bundle> [-l <locale>]] [-t <template>] [-p <plugin dir>] <input files>",
            "Convert input files.", options, hf.getLeftPadding(), hf.getDescPadding(), null);
    pw.flush();/* www .  jav a  2s  . c  o m*/
}

From source file:com.zimbra.cs.account.ldap.upgrade.LdapUpgrade.java

static void usage(ParseException e, UpgradeOp upgradeOp, String errMsg) {

    if (e != null) {
        printer.println("Error parsing command line arguments: " + e.getMessage());
    }/*w w w .  ja v  a  2s  .c  om*/

    if (errMsg != null) {
        printer.println(errMsg);
        printer.println();
    }

    Options opts = getAllOptions();
    PrintWriter pw = printer.getPrintWriter();
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, formatter.getWidth(), getCommandUsage(), null, opts, formatter.getLeftPadding(),
            formatter.getDescPadding(), null);

    pw.flush();
    if (upgradeOp != null) {
        upgradeOp.usage(formatter);
    }
}

From source file:io.github.azige.whitespace.Cli.java

static void printHelp(PrintStream out, Options options) {
    HelpFormatter hf = new HelpFormatter();
    PrintWriter pw = new PrintWriter(out);
    hf.printHelp(pw, hf.getWidth(), "whitespace [-c|-p] <source file>",
            "Whitespace??", options, hf.getLeftPadding(),
            hf.getDescPadding(), null);//  w ww.j ava 2s  .c  o  m
    pw.flush();
}

From source file:com.zimbra.common.localconfig.LocalConfigUpgrade.java

static void usage(String error) {
    if (error != null)
        System.out.println("Error: " + error);
    Options opts = getAllOptions();/*from  w  w  w  .  ja  va 2 s  . c  om*/
    PrintWriter pw = new PrintWriter(System.out, true);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, formatter.getWidth(), getCommandUsage(), null, opts, formatter.getLeftPadding(),
            formatter.getDescPadding(), null);
    pw.flush();
    if (error != null) {
        System.exit(1);
    } else {
        System.exit(0);
    }
}

From source file:cz.pecina.bin.bitwriter.Parameters.java

/**
 * Prints usage information.//w w w  .  j av  a  2  s  . co  m
 *
 * @param stream print stream for the output
 */
public static void usage(final PrintStream stream) {
    log.fine("Printing usage information");
    final HelpFormatter helpFormatter = new HelpFormatter();
    PrintWriter printWriter = new PrintWriter(stream);
    helpFormatter.printHelp(printWriter, helpFormatter.getWidth(), "bitwriter [options] [--] [input-file]...",
            null, options, helpFormatter.getLeftPadding(), helpFormatter.getDescPadding(),
            "(C) 2015 Tom Pecina <tomas@pecina.cz>, license: GNU/GPL");
    printWriter.close();
}

From source file:com.zimbra.cs.redolog.util.PlaybackUtil.java

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

    String usage = "zmplayredo <options>";
    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();

    String trailer = SoapCLI.getAllowedDatetimeFormatsHelp();
    if (trailer != null && trailer.length() > 0) {
        System.err.println();
        System.err.println(trailer);
    }
}

From source file:com.zimbra.qa.unittest.prov.ldap.TestLdapReadTimeout.java

private static void usage(Options options) {
    System.out.println("\n");
    PrintWriter pw = new PrintWriter(System.out, true);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, formatter.getWidth(),
            "zmjava " + TestLdapReadTimeout.class.getCanonicalName() + " [options]", null, options,
            formatter.getLeftPadding(), formatter.getDescPadding(), null);
    System.out.println("\n");
    pw.flush();/*  w  w  w.  j  a v a2 s.c om*/
}

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

private static void printHelpMessage(MigrationOptions options) {
    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, "migration.sh", null, options.getOptions(), leftPadding,
            descPadding, null);/*from   ww w  .jav a  2 s .c  o m*/
    printWriter.flush();
}

From source file:io.mindmaps.graql.GraqlShell.java

public static void runShell(String[] args, String version, GraqlClient client) {

    Options options = new Options();
    options.addOption("n", "name", true, "name of the graph");
    options.addOption("e", "execute", true, "query to execute");
    options.addOption("f", "file", true, "graql file path to execute");
    options.addOption("u", "uri", true, "uri to connect to engine");
    options.addOption("h", "help", false, "print usage message");
    options.addOption("v", "version", false, "print version");

    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;//from ww  w .ja v a2 s.  c o m

    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        return;
    }

    String query = cmd.getOptionValue("e");
    String filePath = cmd.getOptionValue("f");

    // Print usage message if requested or if invalid arguments provided
    if (cmd.hasOption("h") || !cmd.getArgList().isEmpty()) {
        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, "graql.sh", null, options, leftPadding, descPadding, null);
        printWriter.flush();
        return;
    }

    if (cmd.hasOption("v")) {
        System.out.println(version);
        return;
    }

    String namespace = cmd.getOptionValue("n", DEFAULT_NAMESPACE);
    String uriString = cmd.getOptionValue("u", DEFAULT_URI);

    try (GraqlShell shell = new GraqlShell(namespace)) {
        client.connect(shell, new URI("ws://" + uriString + REMOTE_SHELL_URI));

        if (filePath != null) {
            query = loadQuery(filePath);
        }

        if (query != null) {
            shell.executeQuery(query);
            shell.commit();
        } else {
            shell.executeRepl();
        }
    } catch (IOException | InterruptedException | ExecutionException | URISyntaxException e) {
        System.err.println(e.toString());
    } finally {
        client.close();
    }
}

From source file:com.zimbra.cs.service.authenticator.CertUtil.java

private static void usage(Options options) {
    System.out.println("\n");
    PrintWriter pw = new PrintWriter(System.out, true);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(pw, formatter.getWidth(), "zmjava " + CertUtil.class.getCanonicalName() + " [options]",
            null, options, formatter.getLeftPadding(), formatter.getDescPadding(), null);
    System.out.println("\n");
    pw.flush();//  ww  w  .j  av  a2  s. com
}