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

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

Introduction

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

Prototype

public void printUsage(PrintWriter pw, int width, String app, Options options) 

Source Link

Document

Prints the usage statement for the specified application.

Usage

From source file:ekb.elastic.ingest.TaxiQuery.java

public static void main(String... args) {

    Options options = new Options();
    HelpFormatter help = new HelpFormatter();

    try {// ww w  .j av  a 2s .c  o  m
        Option hostOpt = new Option("h", "host", true, "ElasticSearch URL");
        hostOpt.setArgs(1);
        hostOpt.setRequired(true);
        Option portOpt = new Option("p", "port", true, "ElasticSearch URL");
        portOpt.setArgs(1);
        portOpt.setRequired(true);
        Option clusterOpt = new Option("c", "cluster", true, "Cluster");
        clusterOpt.setArgs(1);
        clusterOpt.setRequired(true);
        Option indexOpt = new Option("i", "index", true, "The index");
        indexOpt.setArgs(1);
        indexOpt.setRequired(true);

        Option pickupTimeOpt = new Option("u", "pickup", true, "The pickup time");
        pickupTimeOpt.setArgs(1);
        pickupTimeOpt.setRequired(true);
        Option dropTimeOpt = new Option("d", "dropoff", true, "The dropoff time");
        dropTimeOpt.setArgs(1);
        dropTimeOpt.setRequired(true);

        options.addOption(hostOpt);
        options.addOption(portOpt);
        options.addOption(clusterOpt);
        options.addOption(indexOpt);
        options.addOption(pickupTimeOpt);
        options.addOption(dropTimeOpt);

        GnuParser parser = new GnuParser();
        CommandLine cmd = parser.parse(options, args);

        Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", cmd.getOptionValue('c'))
                .build();
        Client client = new TransportClient(settings).addTransportAddress(new InetSocketTransportAddress(
                cmd.getOptionValue('h'), Integer.parseInt(cmd.getOptionValue('p'))));

        TaxiQuery tq = new TaxiQuery();

        TaxiStats stats = tq.getTaxiStats(client, cmd.getOptionValues("i"));

        log.info("Results:\n" + stats.toDateString());

        sdf.parse(cmd.getOptionValue("u"));
        sdf.parse(cmd.getOptionValue("d"));

        // 2013-01-01T10:10:00

        ArrayList<TaxiBucket> list = tq.getInterval(client, cmd.getOptionValues("index"),
                cmd.getOptionValue("u"), cmd.getOptionValue("d"), 60);

        log.info("List size is: " + list.size());

        client.close();

    } catch (ParseException pe) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        help.printUsage(pw, 80, TaxiQuery.class.getName(), options);

        log.error(sw.toString());

    } catch (TaxiQueryException e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        log.error(sw.toString());
    } catch (java.text.ParseException e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        log.error(sw.toString());
    }
}

From source file:name.martingeisse.ecotools.simulator.ui.Main.java

/**
 * @param options the command-line option definitions
 *//*from w ww  .  j  av a 2  s  .  c  o  m*/
private static void showUsgeAndExit(Options options) {
    PrintWriter w = new PrintWriter(System.out);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printUsage(w, 150, "ecosim.sh", options);
    formatter.printOptions(w, 150, options, 2, 3);
    w.flush();
    System.exit(1);
}

From source file:HDFSFileFinder.java

private static void printUsage(PrintWriter writer) {
    final HelpFormatter usageFormatter = new HelpFormatter();
    usageFormatter.printUsage(writer, 80, name, createCommandLineOptions());
}

From source file:com.momab.dstool.DSTool.java

static void printUsage(Options options, OutputStream out) {

    PrintWriter writer = new PrintWriter(out);
    HelpFormatter formatter = new HelpFormatter();
    formatter.printUsage(writer, 80, CMDLINE_SYNTAX, options);
    writer.flush();//from w  w  w.  j  a va 2  s.c om
}

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

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

    String start = MY_NAME;//from w  w  w. j  a  v a 2s .  c o m
    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  ava 2  s .  c  o  m*/
}

From source file:com.barclays.dfe.fw.DFEWatcher.java

/**
 * Prints the usage.//from w  w  w . j  ava 2  s.  c o m
 *
 * @param applicationName the application name
 * @param options the options
 * @param out the out
 */
public static void printUsage(final String applicationName, final Options options, final OutputStream out) {
    final PrintWriter writer = new PrintWriter(out);
    final HelpFormatter usageFormatter = new HelpFormatter();
    usageFormatter.printUsage(writer, 80, applicationName, options);
    writer.flush();
}

From source file:eu.project.ttc.tools.cli.TermSuiteCLIUtils.java

/**
 * Prints the command line usage to the std error output
 * //from   w  w  w .  j av a  2  s  .  c  om
 * @param e
 *            The error that raised the help message
 * @param cmdLine
 *            The command line usage
 * @param options
 *            The options expected
 */
public static void printUsage(ParseException e, String cmdLine, Options options) {
    System.err.println(e.getMessage());
    // automatically generate the help statement
    HelpFormatter formatter = new HelpFormatter();
    PrintWriter pw = new PrintWriter(System.err);
    formatter.printUsage(pw, cmdLine.length() + 7, cmdLine, options);
    pw.flush();
}

From source file:com.ebay.jetstream.application.CliOptions.java

private void printUsageAndExit(boolean verbose) {
    PrintWriter pw = new PrintWriter(System.err, true);
    HelpFormatter hf = new HelpFormatter();
    hf.printUsage(pw, 72, m_optionHandler.getClass().getCanonicalName(), m_options);
    if (verbose)/*from   w ww.j a  v  a  2  s . c  o  m*/
        hf.printOptions(pw, 72, m_options, 3, 3);
    System.exit(1);
}

From source file:com.cloudera.branchreduce.onezero.Main.java

@Override
public int run(String[] args) throws Exception {
    if (args.length == 0) {
        final PrintWriter writer = new PrintWriter(System.out);
        final HelpFormatter usageFormatter = new HelpFormatter();
        usageFormatter.printUsage(writer, 80, "0-1 Implicit Enumeration", OPTIONS);
        writer.flush();//from   w w w .j  a  v a  2 s.  co  m
        return 1;
    }

    CommandLine cmdLine = (new GnuParser()).parse(OPTIONS, args);

    boolean runLocally = cmdLine.hasOption("local");
    File lpFile = new File(cmdLine.getOptionValue("lpfile"));
    BranchReduceJob<PartialSolution, CurrentBestSolution> job = ImplicitEnumerationSolver.createJob(runLocally,
            lpFile, getConf());
    job.setJobName("BranchReduce: Implicit Enumeration of: " + lpFile.getName());

    if (cmdLine.hasOption("workers")) {
        job.setNumWorkers(new Integer(cmdLine.getOptionValue("workers")));
    }
    if (cmdLine.hasOption("threads")) {
        job.setNumThreads(new Integer(cmdLine.getOptionValue("threads")));
    }
    if (cmdLine.hasOption("memory")) {
        job.setMemory(new Integer(cmdLine.getOptionValue("memory")));
    }

    BranchReduceContext<PartialSolution, CurrentBestSolution> ctxt = job.submit();
    if (ctxt == null) {
        return 1;
    }
    return 0;
}