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

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

Introduction

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

Prototype

public void setSyntaxPrefix(String prefix) 

Source Link

Document

Sets the 'syntaxPrefix'.

Usage

From source file:org.apache.flink.client.FlinkYarnSessionCli.java

private void printUsage() {
    System.out.println("Usage:");
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(200);/*from ww  w  . j  a  va2  s  . co m*/
    formatter.setLeftPadding(5);
    formatter.setSyntaxPrefix("   Required");
    Options req = new Options();
    req.addOption(CONTAINER);
    formatter.printHelp(" ", req);

    formatter.setSyntaxPrefix("   Optional");
    Options opt = new Options();
    opt.addOption(JM_MEMORY);
    opt.addOption(TM_MEMORY);
    opt.addOption(QUERY);
    opt.addOption(QUEUE);
    opt.addOption(SLOTS);
    opt.addOption(DYNAMIC_PROPERTIES);
    opt.addOption(DETACHED);
    opt.addOption(STREAMING);
    opt.addOption(NAME);
    formatter.printHelp(" ", opt);
}

From source file:org.apache.flink.table.client.cli.CliOptionsParser.java

public static void printHelpEmbeddedModeClient() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLeftPadding(5);//  www .  j av  a 2s .  c o  m
    formatter.setWidth(80);

    System.out.println("\nMode \"embedded\" submits Flink jobs from the local machine.");
    System.out.println("\n  Syntax: embedded [OPTIONS]");
    formatter.setSyntaxPrefix("  \"embedded\" mode options:");
    formatter.printHelp(" ", EMBEDDED_MODE_CLIENT_OPTIONS);

    System.out.println();
}

From source file:org.apache.flink.yarn.cli.FlinkYarnCLI.java

private void printUsage() {
    System.out.println("Usage:");
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(200);/*from ww w  . jav a2s.  c om*/
    formatter.setLeftPadding(5);

    formatter.setSyntaxPrefix("   Optional");
    Options options = new Options();
    addGeneralOptions(options);
    addRunOptions(options);
    formatter.printHelp(" ", options);
}

From source file:org.apache.flink.yarn.cli.FlinkYarnSessionCli.java

private void printUsage() {
    System.out.println("Usage:");
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(200);/*from w  w  w  .java  2  s .c o  m*/
    formatter.setLeftPadding(5);
    formatter.setSyntaxPrefix("   Required");
    Options req = new Options();
    req.addOption(CONTAINER);
    formatter.printHelp(" ", req);

    formatter.setSyntaxPrefix("   Optional");
    Options options = new Options();
    addGeneralOptions(options);
    addRunOptions(options);
    formatter.printHelp(" ", options);
}

From source file:org.apache.flink.yarn.Client.java

private void printUsage() {
    System.out.println("Usage:");
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(200);//ww  w .j  av  a  2s  . co m
    formatter.setLeftPadding(5);
    formatter.setSyntaxPrefix("   Required");
    Options req = new Options();
    req.addOption(CONTAINER);
    formatter.printHelp(" ", req);

    formatter.setSyntaxPrefix("   Optional");
    Options opt = new Options();
    opt.addOption(VERBOSE);
    opt.addOption(JM_MEMORY);
    opt.addOption(TM_MEMORY);
    opt.addOption(TM_CORES);
    opt.addOption(QUERY);
    opt.addOption(QUEUE);
    opt.addOption(SLOTS);
    opt.addOption(DYNAMIC_PROPERTIES);
    formatter.printHelp(" ", opt);
}

From source file:org.apache.hadoop.yarn.client.cli.LogsCLI.java

private void printHelpMessage(Options options) {
    System.out.println("Retrieve logs for completed YARN applications.");
    HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("yarn logs -applicationId <application ID> [OPTIONS]", new Options());
    formatter.setSyntaxPrefix("");
    formatter.printHelp("general options are:", options);
}

From source file:org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    Options options = getCommandLineOptions();
    CommandLine cli = parser.parse(options, args);

    Object node = null;//from  ww w.j  a va 2 s  .c o m
    ShutdownThread shutdown = null;
    EquinoxHost equinox = null;
    try {

        if (cli.hasOption("config")) {
            System.setProperty("osgi.configuration.area", cli.getOptionValue("config"));
        }

        while (true) {
            if (cli.hasOption("node")) {
                // Create a node from a configuration URI
                String configurationURI = cli.getOptionValue("node");
                logger.info("SCA Node configuration: " + configurationURI);

                // Create a node launcher
                NodeLauncher launcher = newInstance();
                equinox = launcher.equinoxHost;

                node = launcher.createNode(configurationURI);
            } else if (cli.hasOption("bundles")) {
                /**
                 * osgi.bundles
                 * The comma-separated list of bundles which are automatically installed and optionally started once the system is up
                 * and running. Each entry is of the form:
                 * <URL | simple bundle location>[@ [<start-level>] [":start"]]
                 * If the start-level (>0 integer) is omitted then the framework will use the default start level for the bundle.
                 * If the "start" tag is added then the bundle will be marked as started after being installed. Simple bundle locations are
                 * interepreted as relative to the framework's parent directory. The start-level indicates the OSGi start level at which the
                 * bundle should run. If this value is not set, the system computes an appropriate default.
                 */
                String bundles = cli.getOptionValue("bundles");
                if (bundles != null) {
                    System.setProperty("osgi.bundles", cli.getOptionValue("bundles"));
                }

                // Create a node launcher
                NodeLauncher launcher = newInstance();
                equinox = launcher.equinoxHost;

                /*
                List<String> bundleFiles = cli.getArgList();
                for (String bf : bundleFiles) {
                File f = new File(bf);
                equinox.installBundle(f.toURI().toURL(), null);
                }
                for (Bundle b : launcher.bundleContext.getBundles()) {
                try {
                    if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
                        // Start the non-fragment bundle
                        b.start();
                    }
                } catch (Exception e) {
                    logger.severe(NodeLauncherUtil.string(b, false) + " " + e.getMessage());
                    // logger.log(Level.SEVERE, e.getMessage(), e);
                }
                }
                */

            } else {
                // Create a node from a composite URI and a contribution location
                String compositeURI = cli.getOptionValue("composite");
                List<String> contribs = cli.getArgList();
                Contribution[] contributions = null;
                if (!contribs.isEmpty()) {
                    contributions = new Contribution[contribs.size()];
                    int index = 0;
                    for (String contrib : contribs) {
                        logger.info("SCA contribution: " + contrib);
                        URL url = null;
                        try {
                            url = new URL(contrib);
                        } catch (MalformedURLException e) {
                            url = new File(contrib).toURI().toURL();
                        }
                        contributions[index] = new Contribution("contribution-" + index, url.toString());
                        index++;
                    }
                } else {
                    HelpFormatter formatter = new HelpFormatter();
                    formatter.setSyntaxPrefix("Usage: ");
                    formatter.printHelp("java " + NodeLauncher.class.getName()
                            + " [-config <equinoxConfiguration>]" + " [-c <compositeURI>]" + " [-b <bundles>]"
                            + " [-t <ttl>]" + " contribution1 ... contributionN", options);
                    return;
                }
                // Create a node launcher
                logger.info("SCA composite: " + compositeURI);
                NodeLauncher launcher = newInstance();
                equinox = launcher.equinoxHost;
                node = launcher.createNode(compositeURI, contributions);
            }

            if (node != null) {
                logger.info("Apache Tuscany SCA Node is starting...");

                // Start the node
                try {
                    node.getClass().getMethod("start").invoke(node);
                } catch (Exception e) {
                    logger.log(Level.SEVERE, "SCA Node could not be started", e);
                    throw e;
                }
                logger.info("SCA Node is now started.");
            }
            // Install a shutdown hook
            shutdown = new ShutdownThread(node, equinox);
            Runtime.getRuntime().addShutdownHook(shutdown);

            long ttl = Long.parseLong(cli.getOptionValue("ttl", "-1"));
            if (ttl >= 0) {
                logger.info("Waiting for " + ttl + " milliseconds ...");
                Thread.sleep(ttl);
                break; // Exit
            }

            // Wait until the "Enter" is pressed
            logger.info("Press 'q' to quit, 'r' to restart.");
            int k = 0;
            try {
                while ((k != 'q') && (k != 'r')) {
                    k = System.in.read();
                }
            } catch (IOException e) {

                // Wait forever
                Object lock = new Object();
                synchronized (lock) {
                    lock.wait();
                }
            }

            // Stop the node
            if (node != null) {
                Object n = node;
                node = null;
                stopNode(n);
            }

            // Quit
            if (k == 'q') {
                break;
            }

        }
    } finally {

        // Remove the shutdown hook
        if (shutdown != null) {
            Runtime.getRuntime().removeShutdownHook(shutdown);
        }

        // Stop the node
        if (node != null) {
            destroyNode(node);
        }
        if (equinox != null) {
            equinox.stop();
        }
    }
}

From source file:org.apache.tuscany.sca.node.launcher.NodeLauncher.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new PosixParser();
    Options options = getCommandLineOptions();
    CommandLine cli = parser.parse(options, args);

    Object node = null;//from  ww  w  .j a  v a2 s .c o  m
    ShutdownThread shutdown = null;
    try {
        while (true) {
            if (cli.hasOption("node")) {

                // Create a node from a configuration URI
                String configurationURI = cli.getOptionValue("node");
                logger.info("SCA Node configuration: " + configurationURI);
                // Create a node launcher
                NodeLauncher launcher = newInstance();
                node = launcher.createNodeFromURL(configurationURI);
            } else {

                // Create a node from a composite URI and a contribution location
                String compositeURI = cli.getOptionValue("composite");
                List<String> contribs = cli.getArgList();
                Contribution[] contributions = null;
                if (!contribs.isEmpty()) {
                    contributions = new Contribution[contribs.size()];
                    int index = 0;
                    for (String contrib : contribs) {
                        logger.info("SCA contribution: " + contrib);
                        URL url = null;
                        try {
                            url = new URL(contrib);
                        } catch (MalformedURLException e) {
                            url = new File(contrib).toURI().toURL();
                        }
                        contributions[index] = new Contribution("contribution-" + index, url.toString());
                        index++;
                    }
                } else {
                    HelpFormatter formatter = new HelpFormatter();
                    formatter.setSyntaxPrefix("Usage: ");
                    formatter.printHelp("java " + NodeLauncher.class.getName() + " [-c <compositeURI>]"
                            + " [-s <service>]" + " [-t <ttl>]" + " contribution1 ... contributionN", options);
                    return;
                }
                // Create a node launcher
                logger.info("SCA composite: " + compositeURI);
                NodeLauncher launcher = newInstance();

                node = launcher.createNode(compositeURI, contributions);
            }

            logger.info("Apache Tuscany SCA Node is starting...");

            // Start the node
            try {
                node.getClass().getMethod("start").invoke(node);
            } catch (Exception e) {
                logger.log(Level.SEVERE, "SCA Node could not be started", e);
                throw e;
            }
            logger.info("SCA Node is now started.");

            String service = cli.getOptionValue("service");
            String regex = "(#|\\(|,|\\))";
            if (service != null) {
                // componentName/serviceName/bindingName#methodName(arg0, ..., agrN)
                String tokens[] = service.split(regex);
                String serviceName = tokens[0];
                String operationName = tokens[1];
                String params[] = new String[tokens.length - 2];
                System.arraycopy(tokens, 2, params, 0, params.length);
                logger.info("Invoking service: " + service);
                Method method = node.getClass().getMethod("getService", Class.class, String.class);
                Object proxy = method.invoke(node, null, serviceName);

                Object result = invoke(proxy, operationName, params);
                if (result != null) {
                    logger.info("Result is: " + result);
                }
                break;
            }

            // Install a shutdown hook
            shutdown = new ShutdownThread(node);
            Runtime.getRuntime().addShutdownHook(shutdown);

            long ttl = Long.parseLong(cli.getOptionValue("ttl", "-1"));
            if (ttl >= 0) {
                logger.info("Waiting for " + ttl + " milliseconds ...");
                Thread.sleep(ttl);
                // Stop the node
                if (node != null) {
                    Object n = node;
                    node = null;
                    stopNode(n);
                }
                break; // Exit
            }

            logger.info("Press 'q' to quit, 'r' to restart.");
            int k = 0;
            try {
                while ((k != 'q') && (k != 'r')) {
                    k = System.in.read();
                }
            } catch (IOException e) {

                // Wait forever
                Object lock = new Object();
                synchronized (lock) {
                    lock.wait();
                }
            }

            // Stop the node
            if (node != null) {
                Object n = node;
                node = null;
                stopNode(n);
            }

            // Quit
            if (k == 'q') {
                break;
            }
        }
    } catch (Exception e) {
        // Stop the node
        if (node != null) {
            try {
                Object n = node;
                node = null;
                stopNode(n);
            } catch (Exception e2) {
            }
        }
        throw e;

    } finally {

        // Remove the shutdown hook
        if (shutdown != null) {
            Runtime.getRuntime().removeShutdownHook(shutdown);
        }
    }
}

From source file:org.cimmyt.corehunter.textui.CoreanalyserTextRunner.java

private void showUsage() {
    System.out.println("");
    System.out.println("usage: coreanalyser [options] <file1> [<file2> [<file3>...]]");
    System.out.println("");
    System.out/*  w  ww.  ja v a 2s . c o  m*/
            .println("\texample: The following command will analyse the file core1.csv and the file core2.csv");
    System.out.println("");
    System.out.println("\tcoreanalyser core1.csv core2.csv");
    System.out.println("");

    HelpFormatter f = new HelpFormatter();
    f.setSyntaxPrefix("");

    f.printHelp("options:", opts);
    System.out.println("");
    System.exit(0);
}

From source file:org.cimmyt.corehunter.textui.CorehunterTextRunner.java

private void showUsage() {
    System.out.println("");
    System.out.println("usage: corehunter [options] [measures] <collection_file> <coresubset_file>");
    System.out.println("");
    System.out.println("\texample: The following command will store a coresubset in the file 'coresubset.dat'"
            + "\n\tby selecting 20% (default value) of the accessions from the dataset in the file "
            + "\n\t'collection.dat'.  The accesions will be chosen by attemping to optimize a "
            + "\n\tpseudo-objective function where 70% of the weight is based on Modified Rogers "
            + "\n\tdistance and 30% of the weight is based on Shannons diversity index. Optimization "
            + "\n\tis carried out using the Replica Exchange Monte Carlo algorithm.");
    System.out.println("");
    System.out.println("\tcorehunter -remc -MR 0.7 -SH 0.3 collection.dat coresubset.dat");
    System.out.println("");

    HelpFormatter f = new HelpFormatter();
    f.setSyntaxPrefix("");

    f.printHelp("measures (at least one must be specified):", measuresOpts);
    System.out.println("");
    f.printHelp("search type options:", searchTypeOpts);
    System.out.println("");
    f.printHelp("common advanced search options:", commonSearchOpts);
    System.out.println("");
    f.printHelp("REMC - advanced search options:", remcSearchOpts);
    System.out.println("");
    f.printHelp("Tabu - advanced search options:", tabuSearchOpts);
    System.out.println("");
    f.printHelp("Genetic Algorithm - advanced search options:", genSearchOpts);
    System.out.println("");
    f.printHelp("Merge Replica Search - advanced search options:", mergerepSearchOpts);
    System.out.println("");
    f.printHelp("Mixed Replica Search - advanced search options:", mixrepSearchOpts);
    System.out.println("");
    f.printHelp("(semi) LR Search - advanced search options:", lrSearchOpts);
    System.out.println("");
    f.printHelp("misc options:", miscOpts);
    System.out.println("");
    System.exit(0);//from   w  w  w . j  a  v a2s .  com
}