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

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

Introduction

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

Prototype

int DEFAULT_WIDTH

To view the source code for org.apache.commons.cli HelpFormatter DEFAULT_WIDTH.

Click Source Link

Document

default number of characters per line

Usage

From source file:hivemall.UDTFWithOptions.java

@Nonnull
protected final CommandLine parseOptions(String optionValue) throws UDFArgumentException {
    String[] args = optionValue.split("\\s+");
    Options opts = getOptions();//from w ww  .  jav  a  2  s .  c o  m
    opts.addOption("help", false, "Show function help");
    CommandLine cl = CommandLineUtils.parseOptions(args, opts);

    if (cl.hasOption("help")) {
        Description funcDesc = getClass().getAnnotation(Description.class);
        final String cmdLineSyntax;
        if (funcDesc == null) {
            cmdLineSyntax = getClass().getSimpleName();
        } else {
            String funcName = funcDesc.name();
            cmdLineSyntax = funcName == null ? getClass().getSimpleName()
                    : funcDesc.value().replace("_FUNC_", funcDesc.name());
        }
        StringWriter sw = new StringWriter();
        sw.write('\n');
        PrintWriter pw = new PrintWriter(sw);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, cmdLineSyntax, null, opts,
                HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, true);
        pw.flush();
        String helpMsg = sw.toString();
        throw new UDFArgumentException(helpMsg);
    }

    return cl;
}

From source file:de.static_interface.sinklibrary.api.command.SinkCommandOptions.java

public HelpFormatter getCliHelpFormatter(Writer writer) {
    if (cliHelpFormatter == null) {
        cliHelpFormatter = new HelpFormatter();
        cliHelpFormatter.setNewLine(System.lineSeparator());
        cliHelpFormatter.printHelp(new PrintWriter(writer), HelpFormatter.DEFAULT_WIDTH,
                getCmdLineSyntax().replaceAll("\\{ALIAS\\}", parentCommand.getCmdAlias())
                        .replaceAll("\\{PREFIX\\}", parentCommand.getCommandPrefix()),
                null, getCliOptions(), HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null);
    }/*from ww  w .  ja v  a2s.c  o m*/
    return cliHelpFormatter;
}

From source file:de.static_interface.sinkscripts.scriptengine.scriptcommand.ScriptCommandBase.java

public HelpFormatter getCliHelpFormatter(Writer writer) {
    if (cliHelpFormatter == null) {
        cliHelpFormatter = new HelpFormatter();
        cliHelpFormatter.setNewLine(System.lineSeparator());
        cliHelpFormatter.printHelp(new PrintWriter(writer), HelpFormatter.DEFAULT_WIDTH,
                getSyntax().replaceAll("\\{COMMAND\\}", getName()), null, options,
                HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null);
    }//from w  w w  .j av a2  s .  c  o m
    return cliHelpFormatter;
}

From source file:com.tc.config.DefaultConfigurationProvider.java

@Override
public String getConfigurationParamsDescription() {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    new HelpFormatter().printOptions(printWriter, HelpFormatter.DEFAULT_WIDTH, createOptions(), 1, 5);
    printWriter.close();//from  www. j a  v  a 2 s .  com
    return stringWriter.toString();
}

From source file:com.ottogroup.bi.streaming.runtime.StreamingAppRuntime.java

/**
 * Prints the usage instruction/*w  w  w. j a va 2s.  c  o  m*/
 * @param outputStream
 */
protected void printUsage(final OutputStream outputStream) throws IOException {
    if (outputStream == null)
        throw new IOException("Missing required output stream\n");
    HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(outputStream);
    formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, "streaming-app", "", getOptions(),
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, "");
    pw.flush();
}

From source file:glacierpipe.GlacierPipeMain.java

public static void printHelp(PrintWriter writer) {
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp(writer, HelpFormatter.DEFAULT_WIDTH,
            "<other-command> ... | java -jar glacierpipe.jar [--help | --upload] -e <glacier-endpoint> -v <vault-nane> <archive-name>",
            null, OPTIONS, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null);

    writer.printf("%nBuild-in endpoint aliases:%n%n");
    for (Entry<String, String> entry : ConfigBuilder.GLACIER_ENDPOINTS.entrySet()) {
        writer.printf("  %20s %s%n", entry.getKey() + " ->", entry.getValue());
    }//from w w  w  . ja  v  a  2  s . c  om

    writer.flush();
}

From source file:com.cloudera.cli.validator.components.CommandLineOptions.java

/**
 * Writes usage message to outputstream.
 *
 * @param appName the application name.// w ww .  jav  a  2s.c o  m
 * @param stream output stream.
 * @throws UnsupportedEncodingException
 */
public static void printUsageMessage(String appName, OutputStream stream) throws UnsupportedEncodingException {
    PrintWriter writer = new PrintWriter(
            new BufferedWriter(new OutputStreamWriter(stream, Constants.CHARSET_UTF_8)));
    try {
        String header = "Validates Cloudera Manager Schemas";
        String footer = "";
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(writer, HelpFormatter.DEFAULT_WIDTH, appName, header, OPTIONS,
                HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, footer, true); // auto-usage: whether to also show
                                                                                                                                                                                  // the command line args on the usage line.
    } finally {
        writer.close();
    }
}

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

/**
 * Prints current stubby4j version to the console
 *///  ww  w  .j a v  a 2 s  . com
@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:de.weltraumschaf.jebnf.cli.CliOptions.java

/**
 * Format the command line options./*from  www . j  a v  a  2s  .  c  o m*/
 *
 * Useful to show help message.
 *
 * @param formatter Formatter to format with.
 * @param out Stream to print formatted output.
 */
public void format(final HelpFormatter formatter, final PrintStream out) {
    final PrintWriter writer = new PrintWriter(out);
    formatter.printHelp(writer, HelpFormatter.DEFAULT_WIDTH, EXECUTABLE, HEADER, options,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, FOOTER, true);
    writer.flush();
}

From source file:de.weltraumschaf.registermachine.App.java

private void showHelp() throws IOException {
    final PrintWriter writer = new PrintWriter(getIoStreams().getStdout());
    final HelpFormatter formatter = new HelpFormatter();
    final Version version = new Version("/de/weltraumschaf/registermachine/version.properties");
    version.load();//from w  ww .java  2  s  .  com

    formatter.printHelp(writer, HelpFormatter.DEFAULT_WIDTH, EXECUTABLE,
            String.format(HEADER_FMT, version.toString()), OPTIONS, HelpFormatter.DEFAULT_LEFT_PAD,
            HelpFormatter.DEFAULT_DESC_PAD, FOOTER, true);
    writer.flush();
}