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:org.vivoweb.harvester.util.args.ArgParser.java

/**
 * Get the usage message for this arg list
 * @return the usage string// w  w w.j  a va 2s  . c  om
 */
public String getUsage() {
    HelpFormatter formatter = new HelpFormatter();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(baos);
    formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, this.app, null, getOptions(),
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, false);
    pw.flush();
    return baos.toString();
}

From source file:yrun.YarnRunner.java

@SuppressWarnings("static-access")
public static CommandLine parse(String[] otherArgs, Writer out) {
    Options options = new Options();
    options.addOption(OptionBuilder.isRequired().withArgName("name").hasArg()
            .withDescription("The name of yarn application.").create("n"));
    options.addOption(OptionBuilder.isRequired().withArgName("resourceManagerAddress").hasArg()
            .withDescription("The address of the yarn resource manager.").create("rma"));
    options.addOption(OptionBuilder.isRequired().withArgName("path").hasArg()
            .withDescription("The path where this application will be installed in yarn.").create("p"));
    options.addOption(OptionBuilder.withArgName("queue").hasArg()
            .withDescription("The yarn queue to execute this application.").create("q"));
    options.addOption(OptionBuilder.isRequired().withArgName("command").hasArgs()
            .withDescription("The command to execute in the yarn application.").create("c"));
    options.addOption(OptionBuilder.withArgName("archive").hasArgs()
            .withDescription("The archive(s) to delivery and extract in the application.").create("a"));
    options.addOption(OptionBuilder.withArgName("kill").withDescription("Kill the application on client death.")
            .create("k"));
    options.addOption(//from  w ww . j a v a  2  s . c  o  m
            OptionBuilder.withArgName("help").withDescription("Displays help for this command.").create("h"));

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, otherArgs);
        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            PrintWriter pw = new PrintWriter(out, true);
            formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, "run", null, options,
                    HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, false);
            return null;
        }
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        PrintWriter pw = new PrintWriter(out, true);
        formatter.printHelp(pw, HelpFormatter.DEFAULT_WIDTH, "run", null, options,
                HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, false);
        return null;
    }
    return cmd;
}