Search in sources :

Example 31 with HelpFormatter

use of org.apache.commons.cli.HelpFormatter in project henplus by neurolabs.

the class HenPlus method usageAndExit.

/**
     * @param availableOptions
     */
private void usageAndExit(final Options availableOptions, final int returnCode) {
    final HelpFormatter formatter = new HelpFormatter();
    formatter.printHelp("henplus", availableOptions);
    System.exit(returnCode);
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter)

Example 32 with HelpFormatter

use of org.apache.commons.cli.HelpFormatter in project brisk by riptano.

the class BriskTool method printUsage.

/**
     * Prints usage information to stdout.
     */
private static void printUsage() {
    HelpFormatter hf = new HelpFormatter();
    StringBuilder header = new StringBuilder();
    header.append("\nAvailable commands:\n");
    // No args
    addCmdHelp(header, "jobtracker", "Returns the jobtracker hostname and port");
    addCmdHelp(header, "movejt", "Move the jobtracker and notifies the Task trakers");
    String usage = String.format("java %s [-h|--host=<hostname>] [-p|--port=<#>] <command> <args>%n", BriskTool.class.getSimpleName());
    hf.printHelp(usage, "", options, "");
    System.out.println(header.toString());
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter)

Example 33 with HelpFormatter

use of org.apache.commons.cli.HelpFormatter in project f5less by sky87.

the class TheBuilder method main.

public static void main(String[] argv) throws Exception {
    Options options = new Options();
    options.addOption("js", false, "Create f5less.js");
    options.addOption("p", "port", true, "ws:reload websocket server port");
    options.addOption("h", "host", true, "ws:reload websocket server host");
    options.addOption("d", "debounce", true, "debouncing for commands");
    CommandLine cmdLine = new PosixParser().parse(options, argv);
    String[] args = cmdLine.getArgs();
    if (cmdLine.hasOption("js")) {
        Files.copy(TheBuilder.class.getClassLoader().getResourceAsStream("f5less.js"), Paths.get("./f5less.js"), StandardCopyOption.REPLACE_EXISTING);
        System.out.println("\n  f5less.js created...\n  put the following\n" + "     <script type=\"text/javascript\" src=\"f5less.js\"></script>\n" + "     <script type=\"text/javascript\">f5less.connect()</script>\n" + "  in the page for which you want automatic reloading (assuming 'f5less.js' is in the same directory)\n");
    }
    if (args.length < 2) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("f5less [options] path1 cmd1 path2 cmd2 ...", options);
        System.exit(-1);
    }
    final List<String> reloadPaths = new LinkedList<String>();
    final int commandsDebounce = Integer.parseInt(cmdLine.getOptionValue("d", "100"));
    for (int i = 0; i < args.length / 2; i++) {
        final String path = args[i * 2];
        final String rawCmd = args[i * 2 + 1];
        if (rawCmd.equals("ws:reload"))
            reloadPaths.add(path);
        else
            Watcher.register(path, new CommandListener(path, rawCmd, commandsDebounce));
    }
    ReloadServer reloadServer = null;
    if (!reloadPaths.isEmpty()) {
        reloadServer = new ReloadServer(cmdLine.getOptionValue("h", "localhost"), Integer.parseInt(cmdLine.getOptionValue("p", "9999")), commandsDebounce + 50);
        reloadServer.monitor(reloadPaths);
    }
    System.out.println("Press enter to exit...");
    System.in.read();
    if (reloadServer != null)
        reloadServer.stop();
    Watcher.stop();
    CommandListener.stop();
    System.out.println("Bye bye");
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PosixParser(org.apache.commons.cli.PosixParser) LinkedList(java.util.LinkedList)

Example 34 with HelpFormatter

use of org.apache.commons.cli.HelpFormatter in project flink by apache.

the class CliFrontendParser method printHelpForInfo.

public static void printHelpForInfo() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLeftPadding(5);
    formatter.setWidth(80);
    System.out.println("\nAction \"info\" shows the optimized execution plan of the program (JSON).");
    System.out.println("\n  Syntax: info [OPTIONS] <jar-file> <arguments>");
    formatter.setSyntaxPrefix("  \"info\" action options:");
    formatter.printHelp(" ", getInfoOptionsWithoutDeprecatedOptions(new Options()));
    printCustomCliOptions(formatter, false);
    System.out.println();
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options)

Example 35 with HelpFormatter

use of org.apache.commons.cli.HelpFormatter in project flink by apache.

the class CliFrontendParser method printHelpForSavepoint.

public static void printHelpForSavepoint() {
    HelpFormatter formatter = new HelpFormatter();
    formatter.setLeftPadding(5);
    formatter.setWidth(80);
    System.out.println("\nAction \"savepoint\" triggers savepoints for a running job or disposes existing ones.");
    System.out.println("\n  Syntax: savepoint [OPTIONS] <Job ID> [<target directory>]");
    formatter.setSyntaxPrefix("  \"savepoint\" action options:");
    formatter.printHelp(" ", getSavepointOptionsWithoutDeprecatedOptions(new Options()));
    printCustomCliOptions(formatter, false);
    System.out.println();
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options)

Aggregations

HelpFormatter (org.apache.commons.cli.HelpFormatter)273 Options (org.apache.commons.cli.Options)136 CommandLine (org.apache.commons.cli.CommandLine)126 CommandLineParser (org.apache.commons.cli.CommandLineParser)110 ParseException (org.apache.commons.cli.ParseException)103 GnuParser (org.apache.commons.cli.GnuParser)92 Path (org.apache.hadoop.fs.Path)42 PrintWriter (java.io.PrintWriter)35 Option (org.apache.commons.cli.Option)29 Job (org.apache.hadoop.mapreduce.Job)27 Configuration (org.apache.hadoop.conf.Configuration)21 File (java.io.File)17 IOException (java.io.IOException)14 DefaultParser (org.apache.commons.cli.DefaultParser)13 PosixParser (org.apache.commons.cli.PosixParser)12 FileSystem (org.apache.hadoop.fs.FileSystem)12 BasicParser (org.apache.commons.cli.BasicParser)11 ArrayList (java.util.ArrayList)8 URI (java.net.URI)6 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)6