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

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

Introduction

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

Prototype

int DEFAULT_DESC_PAD

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

Click Source Link

Document

the number of characters of padding to be prefixed to each description line

Usage

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();/*  w  w w  . j  a v a 2  s . c  om*/

    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();
}

From source file:eu.scape_project.tool.toolwrapper.component_uploader.ComponentUploader.java

/**
 * Method used to print command-line syntax (usage) using
 * {@link HelpFormatter}//from   w  w  w. j  a v  a  2s . c o m
 */
private void printUsage() {
    HelpFormatter helpFormatter = new HelpFormatter();

    PrintWriter systemErrPrintWriter = new PrintWriter(
            new OutputStreamWriter(System.err, Charset.defaultCharset()), true);
    helpFormatter.printHelp(systemErrPrintWriter, HelpFormatter.DEFAULT_WIDTH,
            "\"" + getClass().getSimpleName() + ".jar\"", null, options, HelpFormatter.DEFAULT_LEFT_PAD,
            HelpFormatter.DEFAULT_DESC_PAD, Constants.SCAPE_COPYRIGHT_STATEMENT, true);
}

From source file:com.google.caja.plugin.Config.java

public void usage(String msg, PrintWriter out) {
    out.println(BuildInfo.getInstance().getBuildInfo());
    out.println();/*from ww  w.  ja v  a  2 s .c om*/
    if (msg != null && !"".equals(msg)) {
        out.println(msg);
        out.println();
    }
    new HelpFormatter().printHelp(out, HelpFormatter.DEFAULT_WIDTH,
            (mainClass.getSimpleName() + " --input <in.html> [--output_js <out.js> | --out <out>]"), "\n",
            options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, "\n" + usageText, false);
    out.println();
    int maxPlanStateWidth = 0;
    for (Pair<String, String> doc : PipelineMaker.getPreconditionDocumentation()) {
        maxPlanStateWidth = Math.max(maxPlanStateWidth, doc.a.length());
    }
    for (Pair<String, String> doc : PipelineMaker.getGoalDocumentation()) {
        maxPlanStateWidth = Math.max(maxPlanStateWidth, doc.a.length());
    }
    String fmtStr = "%" + maxPlanStateWidth + "s | %s";
    out.println("Preconditions (default to " + PipelineMaker.DEFAULT_PRECONDS + ")");
    for (Pair<String, String> doc : PipelineMaker.getPreconditionDocumentation()) {
        out.println(String.format(fmtStr, doc.a, doc.b));
    }
    out.println();
    out.println("Goals (default to " + PipelineMaker.DEFAULT_GOALS + ")");
    for (Pair<String, String> doc : PipelineMaker.getGoalDocumentation()) {
        out.println(String.format(fmtStr, doc.a, doc.b));
    }
}

From source file:neurord.StochDiff.java

public static void help_exit(Options options, boolean error) {
    String header = "\nwhere the <model> is an XML specification of the model to run. "
            + "The optional <output> specifies where the results should be stored "
            + "(w/o extension). When not supplied, <output> defaults to <model> "
            + "without the extension.\n\n";

    HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(error ? System.err : System.out);
    int columns = Math.max(Math.min(Settings.getEnvironmentVariable("COLUMNS", 80), 120), 20);
    formatter.printHelp(pw, columns,//from  www .ja  va 2s.  co m
            Settings.javaExecutable(StochDiff.class) + " [option...] <model> [<output>]", header, options,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, "");
    pw.flush();

    if (!error) {
        System.out.println();
        Settings.printAvailableSettings(System.out);
    }

    System.exit(error ? 1 : 0);
}

From source file:nl.strohalm.cyclos.setup.Arguments.java

static void printHelp(final Options options) {
    final HelpFormatter formatter = new HelpFormatter();
    formatter.defaultSyntaxPrefix = "";
    formatter.defaultLongOptPrefix = " --";
    final PrintWriter printWriter = new PrintWriter(Setup.getOut());
    formatter.printHelp(printWriter, HelpFormatter.DEFAULT_WIDTH,
            Setup.getResourceBundle().getString("help.header") + ":\n", "", options,
            HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, "", false);
    printWriter.flush();/*w  w w  . ja v  a 2s.c  om*/
    System.exit(1);
}

From source file:openlr.otk.options.UsageBuilder.java

/**
 * Prints the command line syntax./*  w w w .  jav a  2 s  .c o  m*/
 * 
 * @param target
 *            The target stream to write to
 * @param options
 *            The tool options
 * @param argsList
 *            The tool arguments
 * @param toolID
 *            The tool short name
 * @param toolDescription
 *            The description of the tool
 */
public static void usage(final OutputStream target, final Options options, final List<Argument<?>> argsList,
        final String toolID, final String toolDescription) {

    HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(new OutputStreamWriter(target, IOUtils.SYSTEM_DEFAULT_CHARSET));

    String optionsListStr = buildOptionsList(options);
    String argsListStr = buildArgumentsList(argsList);
    formatter.printUsage(pw, HelpFormatter.DEFAULT_WIDTH,
            "java -jar otk-<version>.jar " + toolID + " " + optionsListStr + " " + argsListStr);
    formatter.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, toolDescription);

    if (options.getOptions().size() > 0) {

        formatter.printOptions(pw, HelpFormatter.DEFAULT_WIDTH, options, HelpFormatter.DEFAULT_LEFT_PAD,
                HelpFormatter.DEFAULT_DESC_PAD);
    }

    printArgumentDescriptions(pw, argsList);

    formatter.printWrapped(pw, HelpFormatter.DEFAULT_WIDTH, USAGE_FOOTER);

    pw.flush();
}

From source file:openlr.otk.options.UsageBuilder.java

/**
 * Prints the help for the tool arguments.
 * /* www  .java 2s.c  o  m*/
 * @param pw
 *            The writer to use
 * @param args
 *            The tool arguments
 */
private static void printArgumentDescriptions(final PrintWriter pw, final List<Argument<?>> args) {

    if (args.size() > 0) {

        pw.write(IOUtils.LINE_SEPARATOR);

        // We use the HelpFormatter to format the argument help for us
        // by providing fake options containing the arguments
        Options options = new Options();
        for (Argument<?> argument : args) {
            Option opt = new Option(null, argument.getName(), false, argument.getDescription());
            options.addOption(opt);
        }

        HelpFormatter formatter = new HelpFormatter();
        formatter.setLongOptPrefix("");

        formatter.printOptions(pw, HelpFormatter.DEFAULT_WIDTH, options, HelpFormatter.DEFAULT_LEFT_PAD,
                HelpFormatter.DEFAULT_DESC_PAD);
    }
}

From source file:org.apache.blur.mapreduce.lib.CsvBlurDriver.java

private static CommandLine parse(String... otherArgs) throws ParseException {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("controller*").hasArgs().isRequired(true)
            .withDescription("* Thrift controller connection string. (host1:40010 host2:40010 ...)")
            .create("c"));
    options.addOption(OptionBuilder.withArgName("tablename").hasArg().isRequired(true)
            .withDescription("* Blur table name.").create("t"));
    options.addOption(OptionBuilder.withArgName("family column*").hasArgs().isRequired(true).withDescription(
            "* Define the mapping of fields in the CSV file to column names. (family col1 col2 col3 ...)")
            .create("d"));
    options.addOption(OptionBuilder.withArgName("delimiter").hasArg()
            .withDescription("The file delimiter to be used. (default value ',')  NOTE: For special "
                    + "charactors like the default hadoop separator of ASCII value 1, you can use standard "
                    + "java escaping (\\u0001)")
            .create("s"));
    options.addOption(OptionBuilder.withArgName("path*").hasArg().withDescription(
            "The directory to index, the family name is assumed to BE present in the file contents. (hdfs://namenode/input/in1)")
            .create("i"));
    options.addOption(OptionBuilder.withArgName("family path*").hasArgs().withDescription(
            "The directory to index with a family name, the family name is assumed to NOT be present in the file contents. (family hdfs://namenode/input/in1)")
            .create("I"));
    options.addOption(OptionBuilder.withArgName("auto generate record ids").withDescription(
            "No Record Ids - Automatically generate record ids for each record based on a MD5 has of the data within the record.")
            .create("a"));
    options.addOption(OptionBuilder.withArgName("auto generate row ids").withDescription(
            "No Row Ids - Automatically generate row ids for each record based on a MD5 has of the data within the record.")
            .create("A"));
    options.addOption(OptionBuilder.withArgName("disable optimize indexes during copy")
            .withDescription(//from   w  w w  .  ja  va 2 s. com
                    "Disable optimize indexes during copy, this has very little overhead. (enabled by default)")
            .create("o"));
    options.addOption(OptionBuilder.withArgName("disable index locally")
            .withDescription("Disable the use storage local on the server that is running the reducing "
                    + "task and copy to Blur table once complete. (enabled by default)")
            .create("l"));
    options.addOption(OptionBuilder.withArgName("sequence files inputs")
            .withDescription("The input files are sequence files.").create("S"));
    options.addOption(OptionBuilder.withArgName("size").hasArg()
            .withDescription("The maximum number of Lucene documents to buffer in the reducer for a single "
                    + "row before spilling over to disk. (default 1000)")
            .create("b"));
    options.addOption(OptionBuilder.withArgName("multiplier").hasArg()
            .withDescription("The reducer multipler allows for an increase in the number of reducers per "
                    + "shard in the given table.  For example if the table has 128 shards and the "
                    + "reducer multiplier is 4 the total number of reducers will be 512, 4 reducers "
                    + "per shard. (default 1)")
            .create("r"));
    options.addOption(OptionBuilder.withArgName("minimum maximum").hasArgs(2)
            .withDescription(
                    "Enables a combine file input to help deal with many small files as the input. Provide "
                            + "the minimum and maximum size per mapper.  For a minimum of 1GB and a maximum of "
                            + "2.5GB: (1000000000 2500000000)")
            .create("C"));
    options.addOption(OptionBuilder.withArgName("codec").hasArgs(1).withDescription(
            "Sets the compression codec for the map compress output setting. (SNAPPY,GZIP,BZIP,DEFAULT, or classname)")
            .create("p"));
    options.addOption(OptionBuilder.withArgName("path").hasArg()
            .withDescription(
                    "Sets the output directory for the map reduce job before the indexes are loaded into Blur.")
            .create("out"));
    options.addOption(OptionBuilder.withArgName("path").hasArg()
            .withDescription("Imports the data into Blur after the map reduce job completes.")
            .create("import"));

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, otherArgs);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        PrintWriter pw = new PrintWriter(System.err, true);
        formatter.printHelp(pw, DEFAULT_WIDTH, CSVLOADER, HEADER, options, HelpFormatter.DEFAULT_LEFT_PAD,
                HelpFormatter.DEFAULT_DESC_PAD, null, false);
        return null;
    }

    if (!(cmd.hasOption("I") || cmd.hasOption("i"))) {
        System.err.println("Missing input directory, see options 'i' and 'I'.");
        HelpFormatter formatter = new HelpFormatter();
        PrintWriter pw = new PrintWriter(System.err, true);
        formatter.printHelp(pw, DEFAULT_WIDTH, CSVLOADER, HEADER, options, HelpFormatter.DEFAULT_LEFT_PAD,
                HelpFormatter.DEFAULT_DESC_PAD, null, false);
        return null;
    }
    return cmd;
}

From source file:org.apache.blur.shell.AddColumnDefinitionCommand.java

@SuppressWarnings("static-access")
private static CommandLine parse(String[] otherArgs, Writer out) {
    Options options = new Options();
    options.addOption(OptionBuilder.withArgName("sub column name").hasArg()
            .withDescription("The sub column name of the new column definition.").create("s"));
    options.addOption(OptionBuilder//from   w  ww .  j a  va  2  s.  com
            .withDescription(
                    "Should the column definition be definied as a field less indexing column definition.")
            .create("F"));
    options.addOption(OptionBuilder.withArgName("name value").hasArgs(2)
            .withDescription("Sets the properties for this column definition.").create("p"));
    options.addOption(OptionBuilder
            .withDescription("Should the column definition be definied as a sortable column definition.")
            .create("S"));
    options.addOption(OptionBuilder
            .withDescription("Should the column definition be definied as a multi value column definition.")
            .create("M"));

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

From source file:org.apache.blur.shell.CopyTableCommand.java

@SuppressWarnings("static-access")
public static CommandLine parse(String[] otherArgs, Writer out) {
    Options options = new Options();

    options.addOption(OptionBuilder.isRequired().hasArg().withArgName("tablename")
            .withDescription("* Source table name.").create("src"));

    options.addOption(OptionBuilder.isRequired().hasArg().withArgName("tablename")
            .withDescription("* Target table name.").create("dest"));

    options.addOption(OptionBuilder.isRequired().hasArg().withArgName("cluster")
            .withDescription("* Target cluster for new table.").create("c"));

    options.addOption(OptionBuilder.hasArg().isRequired().withArgName("uri")
            .withDescription("The location of the target table. (Example hdfs://namenode/blur/tables/table)")
            .create("l"));

    options.addOption(OptionBuilder.withDescription("Displays help for this command.").create("h"));

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;//from w  w  w.  j  av a 2s .c  o  m
    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, "copy", 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, "copy", null, options,
                HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null, false);
        return null;
    }
    return cmd;
}