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

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

Introduction

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

Prototype

public void printWrapped(PrintWriter pw, int width, String text) 

Source Link

Document

Print the specified text to the specified PrintWriter.

Usage

From source file:boa.BoaMain.java

protected static final void printHelp(final Options options, final String message) {
    if (message != null)
        System.err.println(message);

    final HelpFormatter help = new HelpFormatter();

    final PrintWriter pw = new PrintWriter(System.out);
    help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, "The available options are:");
    help.printOptions(pw, HelpFormatter.DEFAULT_WIDTH, options, HelpFormatter.DEFAULT_LEFT_PAD,
            HelpFormatter.DEFAULT_DESC_PAD);
    help.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH,
            "\nPlease report issues at http://www.github.com/boalang/compiler");
    pw.flush();/*w ww . j  av  a  2  s.c o  m*/
}

From source file:com.genentech.chemistry.openEye.apps.SDFCatsIndexer.java

private static void exitWithHelp(Options options) {
    int width = 100;

    String start = MY_NAME;/*from  ww w  . j av a  2  s .  c om*/
    String head = "Will generate CATS Fingerprints for input compounds.";

    HelpFormatter formatter = new HelpFormatter();
    formatter.setArgName("p");
    PrintWriter out = new PrintWriter(System.err, true);
    formatter.printUsage(out, width, start, options);
    formatter.printWrapped(out, width, head);
    formatter.printOptions(out, width, options, 2, 2);
    System.exit(1);
}

From source file:com.genentech.chemistry.openEye.apps.SDFTopologicalIndexer.java

private static void exitWithHelp(Options options) {
    int width = 100;

    StringBuilder types = new StringBuilder();
    types.append("'all' or one or multiple of: ");
    for (String typ : AVAILIndexes)
        types.append(typ).append(" ");

    String start = MY_NAME + " all|IndexTypes";
    String head = "Will generate topological indexes for input compounds.";

    HelpFormatter formatter = new HelpFormatter();
    formatter.setArgName("p");
    PrintWriter out = new PrintWriter(System.err, true);
    formatter.printUsage(out, width, start, options);
    formatter.printWrapped(out, width, head);
    formatter.printOptions(out, width, options, 2, 2);
    formatter.printWrapped(out, width, 18, "  IndexTypes:     " + types.toString());
    System.exit(1);//from w w  w  .j a va  2  s .co m
}

From source file:com.net2plan.cli.CLINet2Plan.java

private String getModeHelp(String mode) {
    if (!modes.containsKey(mode))
        throw new IllegalModeException("Bad mode - " + mode);

    try {//w  w  w.  j a v  a 2 s.  c  o  m
        ICLIModule modeInstance = modes.get(mode).newInstance();
        Options modeOptions = modeInstance.getCommandLineOptions();
        String modeHelp = modeInstance.getCommandLineHelp();

        StringWriter sw = new StringWriter();
        try (PrintWriter w = new PrintWriter(sw)) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printWrapped(w, LINE_WIDTH, "Mode: " + mode);
            formatter.printWrapped(w, LINE_WIDTH, "");
            formatter.printWrapped(w, LINE_WIDTH, modeHelp);
            formatter.printWrapped(w, LINE_WIDTH, "");
            formatter.printHelp(w, LINE_WIDTH, "java -jar Net2Plan-cli.jar --mode " + mode, null, modeOptions,
                    0, 1, null, true);

            w.flush();
        }

        return (sw.toString());
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:io.github.azagniotov.stubby4j.cli.CommandLineInterpreter.java

/**
 * Prints current stubby4j version to the console
 *///from  w  w w. ja v  a2s .co  m
@CoberturaIgnore
public void printVersion() {
    final HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(System.out);
    formatter.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, JarUtils.readManifestImplementationVersion());
    pw.flush();
}

From source file:info.mikaelsvensson.devtools.analysis.shared.CommandLineUtil.java

public CommandLine parseArgs(String[] args, String usageHelp, Class<?> appClass, Option... opts)
        throws CommandLineException {
    final Options options = new Options();
    try {/*from  w ww . j ava2  s  .c o  m*/
        for (Option opt : opts) {
            options.addOption(opt);
        }

        CommandLineParser commandLineParser = new GnuParser();
        final CommandLine commandLine = commandLineParser.parse(options, args);
        return commandLine;
    } catch (ParseException e) {
        StringWriter writer = new StringWriter();
        final PrintWriter pw = new PrintWriter(writer);
        pw.println("ERROR:");
        pw.println(e.getMessage());

        HelpFormatter helpFormatter = new HelpFormatter();
        pw.println();
        pw.println("ABOUT:");
        final int consoleWidth = 120;
        helpFormatter.printWrapped(pw, consoleWidth, usageHelp);
        pw.println();
        helpFormatter.printUsage(pw, consoleWidth, "java " + appClass.getName(), options);
        pw.println();
        pw.println("ARGUMENTS:");
        helpFormatter.printOptions(pw, consoleWidth, options, 0, 1);
        pw.close();
        throw new CommandLineException("Could not parse command line", writer.toString(), e);
    }
}

From source file:com.net2plan.cli.CLINet2Plan.java

private String getMainHelp() {
    final StringBuilder help = new StringBuilder();

    HelpFormatter formatter = new HelpFormatter();
    StringWriter sw = new StringWriter();
    PrintWriter w = new PrintWriter(sw);
    formatter.printWrapped(w, LINE_WIDTH, "Net2Plan " + new Version().toString() + " Command-Line Interface");
    formatter.printWrapped(w, LINE_WIDTH, "");
    if (modes.isEmpty()) {
        formatter.printWrapped(w, LINE_WIDTH, "No CLI tool is available");
    } else {//from ww  w .ja  v a 2  s .  co m
        formatter.printHelp(w, LINE_WIDTH, "java -jar Net2Plan-cli.jar", null, options, 0, 1, null, true);
        formatter.printWrapped(w, LINE_WIDTH, "");
        formatter.printWrapped(w, LINE_WIDTH,
                "Select 'help' to show this information, or 'mode' to execute a specific tool. Optionally, if 'help' is accompanied of a mode name, the help information for this mode is shown");
    }
    w.flush();
    help.append(sw.toString());

    return help.toString();
}

From source file:net.freehal.ui.common.Main.java

private void printHelp(Options options) {
    final String header = "FreeHAL is a self-learning conversation simulator, " + "an artificial intelligence "
            + "which uses semantic nets to organize its knowledge.";
    final String footer = "Please report bugs to <info@freehal.net>.";
    final int width = 120;
    final int descPadding = 5;
    final PrintWriter out = new PrintWriter(System.out, true);

    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(width);//from  w  w w  . ja  v  a 2s  .co m
    formatter.setDescPadding(descPadding);
    formatter.printUsage(out, width, "java " + Main.class.getName(), options);
    formatter.printWrapped(out, width, header);
    formatter.printWrapped(out, width, "");
    formatter.printOptions(out, width, options, formatter.getLeftPadding(), formatter.getDescPadding());
    formatter.printWrapped(out, width, "");
    formatter.printWrapped(out, width, footer);
}

From source file:com.aleerant.tnssync.PropertiesHandler.java

private void printUsageInfo() {
    final String header = "\n" + APP_NAME + " creates " + APP_TNSNAMES_FILENAME
            + " file for services listed in a config file (" + APP_TNSSYNC_FILENAME
            + ") getting Oracle Net Description data from a directory server (described in "
            + APP_LDAPORA_FILENAME + ").\n\n";
    final String footer = "\n"
            + "Licensed under the Apache License Version 2.0, http://www.apache.org/licenses/LICENSE-2.0";
    final String warning_msg = "WARNING: " + APP_NAME + " is able to owerwrite the existing "
            + APP_TNSNAMES_FILENAME + " file!\n\n";
    final String logging_msg = APP_NAME
            + " provides logging functionality using Simple Logging Facade for Java (SLF4J) with a logback backend. "
            + "Logback looks for a configuration file named " + APP_TNSSYNC_LOGBACK_FILENAME
            + " in TNS_ADMIN directory.\n\n";
    final int width = 120;
    final PrintWriter writer = new PrintWriter(System.out);

    HelpFormatter formatter = new HelpFormatter();
    formatter.printUsage(writer, width, "java -jar " + APP_NAME + ".jar [-ta <DIR>]");
    formatter.printUsage(writer, width, "java -jar " + APP_NAME + ".jar -h");
    formatter.printUsage(writer, width, "java -jar " + APP_NAME + ".jar -v");
    formatter.printWrapped(writer, width, header);
    formatter.printWrapped(writer, width, warning_msg);
    formatter.printWrapped(writer, width, logging_msg);
    formatter.printOptions(writer, width, mOptions, 1, 3);
    formatter.printWrapped(writer, width, footer);
    writer.close();/*w  w w  .  ja  v  a 2  s .  c  om*/
}

From source file:nl.imvertor.common.Configurator.java

private void dieOnCli(String infotype) {
    HelpFormatter formatter = new HelpFormatter();
    int width = 118;
    int leftpad = 2;
    int descpad = 4;

    if (infotype.equals("program")) {
        formatter.printHelp(pw, width, "Imvertor -param [value] (-param [value]...)", "Imvertor", options,
                leftpad, descpad, "");
    } else if (infotype.equals("license")) {
        formatter.printWrapped(pw, width,
                "The following information is shown because you specified -help license at the command line.");
        formatter.printWrapped(pw, width, "");
        formatter.printWrapped(pw, width, Release.getDetails());
        formatter.printWrapped(pw, width, "");
        formatter.printWrapped(pw, width, "Imvertor exits.");
    } else { // assume "error"
        formatter.printWrapped(pw, width, "Error occurred processing the command line. ");
        formatter.printWrapped(pw, width, "Please specify:\nImvertor -param [value] (-param [value]...)");
        formatter.printWrapped(pw, width, "Pass -help program for an overview of all program parameters.");
        formatter.printWrapped(pw, width, "Imvertor exits.");
    }/*w  w w.j  a va  2  s . com*/

    pw.flush();
    System.exit(-1);
}