Example usage for org.apache.commons.cli2.util HelpFormatter HelpFormatter

List of usage examples for org.apache.commons.cli2.util HelpFormatter HelpFormatter

Introduction

In this page you can find the example usage for org.apache.commons.cli2.util HelpFormatter HelpFormatter.

Prototype

public HelpFormatter(final String gutterLeft, final String gutterCenter, final String gutterRight,
        final int fullWidth) 

Source Link

Document

Creates a new HelpFormatter using the specified parameters

Usage

From source file:broadwick.CliOptions.java

/**
 * Construct and provide GNU-compatible Options. Read the command line extracting the arguments, this
 * additionally displays the help message if the command line is empty.
 *
 * @param args the command line arguments.
 *//*from   ww w .j  a v a 2 s .co m*/
public CliOptions(final String[] args) {
    buildCommandLineArguments();

    final Parser parser = new Parser();
    parser.setGroup(options);
    final HelpFormatter hf = new HelpFormatter(SPACE, SPACE, SPACE, LINEWIDTH);
    parser.setHelpFormatter(hf);
    parser.setHelpTrigger("--help");
    cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        hf.printHeader();
        throw new BroadwickException("Empty command line.");
    }

    validateCommandLineArguments();
}

From source file:it.geosolutions.utils.db.BaseArgumentsManager.java

private void finishOptInitialization() {
    // /////////////////////////////////////////////////////////////////////
    ////from  w w w  .  j a  v a2  s. c  o m
    // Help Formatter
    //
    // /////////////////////////////////////////////////////////////////////
    final HelpFormatter cmdHlp = new HelpFormatter("| ", "  ", " |", 75);
    cmdHlp.setShellCommand(getToolName());
    cmdHlp.setHeader("Help");
    cmdHlp.setFooter(new StringBuffer(getToolName() + " - GeoSolutions S.a.s (C) 2009-2013 - v ")
            .append(getVersion()).toString());
    cmdHlp.setDivider("|-------------------------------------------------------------------------|");

    // /////////////////////////////////////////////////////////////////////
    //
    // Close Parser
    //
    // /////////////////////////////////////////////////////////////////////
    optionsGroup = new GroupImpl(cmdOpts, "Options", "All the options", 1, cmdOpts.size());
    cmdParser.setGroup(optionsGroup);
    cmdParser.setHelpOption(helpOpt);
    cmdParser.setHelpFormatter(cmdHlp);

}

From source file:com.cloudera.knittingboar.conf.cmdline.DataConverterCmdLineDriver.java

private static boolean parseArgs(String[] args) throws IOException {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    // Option quiet =
    // builder.withLongName("quiet").withDescription("be extra quiet").create();
    // Option scores =
    // builder.withLongName("scores").withDescription("output score diagnostics during training").create();

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFileOption = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get input data").create();

    Option outputFileOption = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to write output data").create();

    Option recordsPerBlockOption = builder.withLongName("recordsPerBlock")
            .withArgument(/*from ww w.  j  a v a 2s . c o m*/
                    argumentBuilder.withName("recordsPerBlock").withDefault("20000").withMaximum(1).create())
            .withDescription("the number of records per output file shard to write").create();

    // optionally can be { 20Newsgroups, rcv1 }
    Option RecordFactoryType = builder
            .withLongName("datasetType").withArgument(argumentBuilder.withName("recordFactoryType")
                    .withDefault("20Newsgroups").withMaximum(1).create())
            .withDescription("the type of dataset to convert").create();

    /*
     * Option passes = builder.withLongName("passes") .withArgument(
     * argumentBuilder.withName("passes") .withDefault("2")
     * .withMaximum(1).create())
     * .withDescription("the number of times to pass over the input data")
     * .create();
     * 
     * Option lambda = builder.withLongName("lambda")
     * .withArgument(argumentBuilder
     * .withName("lambda").withDefault("1e-4").withMaximum(1).create())
     * .withDescription("the amount of coefficient decay to use") .create();
     * 
     * Option rate = builder.withLongName("rate")
     * .withArgument(argumentBuilder.withName
     * ("learningRate").withDefault("1e-3").withMaximum(1).create())
     * .withDescription("the learning rate") .create();
     * 
     * Option noBias = builder.withLongName("noBias")
     * .withDescription("don't include a bias term") .create();
     */

    Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption)
            .withOption(outputFileOption).withOption(recordsPerBlockOption).withOption(RecordFactoryType)
            .create();

    Parser parser = new Parser();
    parser.setHelpOption(help);
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {

        System.out.println("null!");
        return false;
    }

    // "/Users/jpatterson/Downloads/datasets/20news-bydate/20news-bydate-train/"
    strInputFile = getStringArgument(cmdLine, inputFileOption);

    // "/Users/jpatterson/Downloads/datasets/20news-kboar/train4/"
    strOutputFile = getStringArgument(cmdLine, outputFileOption);

    strrecordsPerBlock = getStringArgument(cmdLine, recordsPerBlockOption);

    return true;
}

From source file:com.cloudera.knittingboar.conf.cmdline.ModelTrainerCmdLineDriver.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    // Option quiet =
    // builder.withLongName("quiet").withDescription("be extra quiet").create();
    // Option scores =
    // builder.withLongName("scores").withDescription("output score diagnostics during training").create();

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFile = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option outputFile = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option features = builder.withLongName("features")
            .withArgument(argumentBuilder.withName("numFeatures").withDefault("1000").withMaximum(1).create())
            .withDescription("the number of internal hashed features to use").create();

    // optionally can be { 20Newsgroups, rcv1 }
    Option RecordFactoryType = builder.withLongName("recordFactoryType")
            .withArgument(argumentBuilder.withName("recordFactoryType").withDefault("20Newsgroups")
                    .withMaximum(1).create())
            .withDescription("the record vectorization factory to use").create();

    Option passes = builder.withLongName("passes")
            .withArgument(argumentBuilder.withName("passes").withDefault("2").withMaximum(1).create())
            .withDescription("the number of times to pass over the input data").create();

    Option lambda = builder.withLongName("lambda")
            .withArgument(argumentBuilder.withName("lambda").withDefault("1e-4").withMaximum(1).create())
            .withDescription("the amount of coefficient decay to use").create();

    Option rate = builder.withLongName("rate")
            .withArgument(argumentBuilder.withName("learningRate").withDefault("1e-3").withMaximum(1).create())
            .withDescription("the learning rate").create();

    Option noBias = builder.withLongName("noBias").withDescription("don't include a bias term").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFile).withOption(outputFile)
            .withOption(RecordFactoryType).withOption(passes).withOption(lambda).withOption(rate)
            .withOption(noBias).withOption(features).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);/*from  ww  w. j av  a  2  s .  c o m*/
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {

        System.out.println("null!");
        return false;
    }

    input_dir = getStringArgument(cmdLine, inputFile);
    output_dir = getStringArgument(cmdLine, outputFile);

    /*
     * TrainLogistic.inputFile = getStringArgument(cmdLine, inputFile);
     * TrainLogistic.outputFile = getStringArgument(cmdLine, outputFile);
     * 
     * List<String> typeList = Lists.newArrayList(); for (Object x :
     * cmdLine.getValues(types)) { typeList.add(x.toString()); }
     * 
     * List<String> predictorList = Lists.newArrayList(); for (Object x :
     * cmdLine.getValues(predictors)) { predictorList.add(x.toString()); }
     * 
     * lmp = new LogisticModelParameters();
     * lmp.setTargetVariable(getStringArgument(cmdLine, target));
     * lmp.setMaxTargetCategories(getIntegerArgument(cmdLine,
     * targetCategories)); lmp.setNumFeatures(getIntegerArgument(cmdLine,
     * features)); lmp.setUseBias(!getBooleanArgument(cmdLine, noBias));
     * lmp.setTypeMap(predictorList, typeList);
     * 
     * lmp.setLambda(getDoubleArgument(cmdLine, lambda));
     * lmp.setLearningRate(getDoubleArgument(cmdLine, rate));
     * 
     * TrainLogistic.scores = getBooleanArgument(cmdLine, scores);
     * TrainLogistic.passes = getIntegerArgument(cmdLine, passes);
     */
    return true;
}

From source file:it.jnrpe.server.console.PluginCommand.java

public String getCommandLine() {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();

    Group g = getCommandLineGroup();
    HelpFormatter hf = new HelpFormatter(null, null, null, getConsole().getTerminal().getWidth());
    hf.setGroup(g);//from  ww w.  j  ava 2  s.  c o  m
    hf.setPrintWriter(new PrintWriter(new OutputStreamWriter(bout, charset)));
    hf.printUsage();

    String usage = new String(bout.toByteArray(), charset);

    String[] lines = usage.split("\\n");

    StringBuilder res = new StringBuilder();

    for (int i = 1; i < lines.length; i++) {
        res.append(lines[i]);
    }

    return res.toString();
}

From source file:com.memonews.mahout.sentiment.SentimentModelTester.java

boolean parseArgs(final String[] args) {
    final DefaultOptionBuilder builder = new DefaultOptionBuilder();

    final Option help = builder.withLongName("help").withDescription("print this list").create();

    final ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    final Option inputFileOption = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    final Option modelFileOption = builder.withLongName("model").withRequired(true)
            .withArgument(argumentBuilder.withName("model").withMaximum(1).create())
            .withDescription("where to get a model").create();

    final Group normalArgs = new GroupBuilder().withOption(help).withOption(inputFileOption)
            .withOption(modelFileOption).create();

    final Parser parser = new Parser();
    parser.setHelpOption(help);//from  w  ww. ja v a  2s  .c om
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    final CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        return false;
    }

    inputFile = (String) cmdLine.getValue(inputFileOption);
    modelFile = (String) cmdLine.getValue(modelFileOption);
    return true;
}

From source file:com.ml.ira.algos.RunLogistic.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create();

    Option auc = builder.withLongName("auc").withDescription("print AUC").create();
    Option confusion = builder.withLongName("confusion").withDescription("print confusion matrix").create();

    Option scores = builder.withLongName("scores").withDescription("print scores").create();

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFileOption = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option modelFileOption = builder.withLongName("model").withRequired(true)
            .withArgument(argumentBuilder.withName("model").withMaximum(1).create())
            .withDescription("where to get a model").create();

    Option fieldNames = builder.withLongName("fdnames").withRequired(true)
            .withArgument(argumentBuilder.withName("fns").create())
            .withDescription("the field names of training data set").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(auc).withOption(scores)
            .withOption(confusion).withOption(inputFileOption).withOption(modelFileOption)
            .withOption(fieldNames).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);/*from  w ww  .  j  a v  a  2s  .  c o  m*/
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        return false;
    }

    inputFile = getStringArgument(cmdLine, inputFileOption);
    modelFile = getStringArgument(cmdLine, modelFileOption);
    showAuc = getBooleanArgument(cmdLine, auc);
    showScores = getBooleanArgument(cmdLine, scores);
    showConfusion = getBooleanArgument(cmdLine, confusion);
    RunLogistic.fieldNames = getStringArgument(cmdLine, fieldNames);

    System.out.println("inputFile: " + inputFile);
    System.out.println("modelFile: " + modelFile);
    System.out.println("fieldNames: " + RunLogistic.fieldNames);

    return true;
}

From source file:haflow.component.mahout.logistic.RunLogistic.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create();

    Option auc = builder.withLongName("auc").withDescription("print AUC").create();
    Option confusion = builder.withLongName("confusion").withDescription("print confusion matrix").create();

    Option scores = builder.withLongName("scores").withDescription("print scores").create();

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFileOption = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option modelFileOption = builder.withLongName("model").withRequired(true)
            .withArgument(argumentBuilder.withName("model").withMaximum(1).create())
            .withDescription("where to get a model").create();
    Option outputFileOption = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to store predicting data").create();
    Option accurateFileOption = builder.withLongName("accurate").withRequired(true)
            .withArgument(argumentBuilder.withName("accurate").withMaximum(1).create())
            .withDescription("where to store accurate information").create();
    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(auc).withOption(scores)
            .withOption(confusion).withOption(inputFileOption).withOption(modelFileOption)
            .withOption(outputFileOption).withOption(accurateFileOption).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);/*from  w  ww  .  ja v  a 2  s .  c  om*/
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        return false;
    }

    inputFile = getStringArgument(cmdLine, inputFileOption);
    modelFile = getStringArgument(cmdLine, modelFileOption);
    outputFile = getStringArgument(cmdLine, outputFileOption);
    accurateFile = getStringArgument(cmdLine, accurateFileOption);
    showAuc = getBooleanArgument(cmdLine, auc);
    showScores = getBooleanArgument(cmdLine, scores);
    showConfusion = getBooleanArgument(cmdLine, confusion);

    return true;
}

From source file:it.jnrpe.server.console.PluginCommand.java

public void printHelp() throws IOException {
    Group g = getCommandLineGroup();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    HelpFormatter hf = new HelpFormatter("  ", null, null, getConsole().getTerminal().getWidth());
    hf.setGroup(g);/*from  w  ww  .ja va 2 s .c o  m*/

    PrintWriter pw = new PrintWriter(new OutputStreamWriter(bout, charset));
    hf.setPrintWriter(pw);
    hf.printHelp();

    pw.flush();

    // getConsole().println("\u001B[1mCommand Line:\u001B[0m ");
    getConsole().println(highlight("Command Line: "));
    getConsole().println("  " + getName() + " " + getCommandLine());
    getConsole().println(highlight("Usage:"));
    getConsole().println(new String(bout.toByteArray(), charset));

}

From source file:haflow.component.mahout.logistic.TrainLogistic.java

private static boolean parseArgs(String[] args) {
    DefaultOptionBuilder builder = new DefaultOptionBuilder();

    Option help = builder.withLongName("help").withDescription("print this list").create();

    Option quiet = builder.withLongName("quiet").withDescription("be extra quiet").create();
    Option scores = builder.withLongName("scores").withDescription("output score diagnostics during training")
            .create();/*from w w w.  j  ava  2 s. co m*/

    ArgumentBuilder argumentBuilder = new ArgumentBuilder();
    Option inputFile = builder.withLongName("input").withRequired(true)
            .withArgument(argumentBuilder.withName("input").withMaximum(1).create())
            .withDescription("where to get training data").create();

    Option outputFile = builder.withLongName("output").withRequired(true)
            .withArgument(argumentBuilder.withName("output").withMaximum(1).create())
            .withDescription("where to get training data").create();
    Option inforFile = builder.withLongName("infor").withRequired(true)
            .withArgument(argumentBuilder.withName("infor").withMaximum(1).create())
            .withDescription("where to store information about the training").create();

    Option predictors = builder.withLongName("predictors").withRequired(true)
            .withArgument(argumentBuilder.withName("p").create())
            .withDescription("a list of predictor variables").create();

    Option types = builder.withLongName("types").withRequired(true)
            .withArgument(argumentBuilder.withName("t").create())
            .withDescription("a list of predictor variable types (numeric, word, or text)").create();

    Option target = builder.withLongName("target").withRequired(true)
            .withArgument(argumentBuilder.withName("target").withMaximum(1).create())
            .withDescription("the name of the target variable").create();

    Option features = builder.withLongName("features")
            .withArgument(argumentBuilder.withName("numFeatures").withDefault("1000").withMaximum(1).create())
            .withDescription("the number of internal hashed features to use").create();

    Option passes = builder.withLongName("passes")
            .withArgument(argumentBuilder.withName("passes").withDefault("2").withMaximum(1).create())
            .withDescription("the number of times to pass over the input data").create();

    Option lambda = builder.withLongName("lambda")
            .withArgument(argumentBuilder.withName("lambda").withDefault("1e-4").withMaximum(1).create())
            .withDescription("the amount of coefficient decay to use").create();

    Option rate = builder.withLongName("rate")
            .withArgument(argumentBuilder.withName("learningRate").withDefault("1e-3").withMaximum(1).create())
            .withDescription("the learning rate").create();

    Option noBias = builder.withLongName("noBias").withDescription("don't include a bias term").create();

    Option targetCategories = builder.withLongName("categories").withRequired(true)
            .withArgument(argumentBuilder.withName("number").withMaximum(1).create())
            .withDescription("the number of target categories to be considered").create();

    Group normalArgs = new GroupBuilder().withOption(help).withOption(quiet).withOption(inputFile)
            .withOption(outputFile).withOption(inforFile).withOption(target).withOption(targetCategories)
            .withOption(predictors).withOption(types).withOption(passes).withOption(lambda).withOption(rate)
            .withOption(noBias).withOption(features).create();

    Parser parser = new Parser();
    parser.setHelpOption(help);
    parser.setHelpTrigger("--help");
    parser.setGroup(normalArgs);
    parser.setHelpFormatter(new HelpFormatter(" ", "", " ", 130));
    CommandLine cmdLine = parser.parseAndHelp(args);

    if (cmdLine == null) {
        return false;
    }

    TrainLogistic.inputFile = getStringArgument(cmdLine, inputFile);
    TrainLogistic.outputFile = getStringArgument(cmdLine, outputFile);
    TrainLogistic.inforFile = getStringArgument(cmdLine, inforFile);

    List<String> typeList = Lists.newArrayList();
    for (Object x : cmdLine.getValues(types)) {
        typeList.add(x.toString());
    }

    List<String> predictorList = Lists.newArrayList();
    for (Object x : cmdLine.getValues(predictors)) {
        predictorList.add(x.toString());
    }

    lmp = new LogisticModelParameters();
    lmp.setTargetVariable(getStringArgument(cmdLine, target));
    lmp.setMaxTargetCategories(getIntegerArgument(cmdLine, targetCategories));
    lmp.setNumFeatures(getIntegerArgument(cmdLine, features));
    lmp.setUseBias(!getBooleanArgument(cmdLine, noBias));
    lmp.setTypeMap(predictorList, typeList);

    lmp.setLambda(getDoubleArgument(cmdLine, lambda));
    lmp.setLearningRate(getDoubleArgument(cmdLine, rate));

    TrainLogistic.scores = getBooleanArgument(cmdLine, scores);
    TrainLogistic.passes = getIntegerArgument(cmdLine, passes);
    System.out.print("infor:" + TrainLogistic.inforFile);

    System.out.println("target:" + getStringArgument(cmdLine, target));
    System.out.println("targetCategories:" + String.valueOf(getStringArgument(cmdLine, targetCategories)));
    System.out.println("features:" + String.valueOf(getStringArgument(cmdLine, features)));
    System.out.println("lambda:" + String.valueOf(getStringArgument(cmdLine, lambda)));
    System.out.println("rate:" + String.valueOf(getStringArgument(cmdLine, rate)));
    return true;
}