Search in sources :

Example 66 with Options

use of org.apache.commons.cli.Options in project heron by twitter.

the class SchedulerMain method main.

public static void main(String[] args) throws Exception {
    // construct the options and help options first.
    Options options = constructOptions();
    Options helpOptions = constructHelpOptions();
    // parse the options
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(helpOptions, args, true);
    // print help, if we receive wrong set of arguments
    if (cmd.hasOption("h")) {
        usage(options);
        return;
    }
    // Now parse the required options
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        throw new RuntimeException("Error parsing command line options: ", e);
    }
    // It returns a new empty Properties instead of null,
    // if no properties passed from command line. So no need for null check.
    Properties schedulerProperties = cmd.getOptionProperties(SchedulerUtils.SCHEDULER_COMMAND_LINE_PROPERTIES_OVERRIDE_OPTION);
    // initialize the scheduler with the options
    String topologyName = cmd.getOptionValue("topology_name");
    SchedulerMain schedulerMain = createInstance(cmd.getOptionValue("cluster"), cmd.getOptionValue("role"), cmd.getOptionValue("environment"), cmd.getOptionValue("topology_bin"), topologyName, Integer.parseInt(cmd.getOptionValue("http_port")), cmd.hasOption("verbose"), schedulerProperties);
    LOG.info("Scheduler command line properties override: " + schedulerProperties.toString());
    // run the scheduler
    boolean ret = schedulerMain.runScheduler();
    // Log the result and exit
    if (!ret) {
        throw new RuntimeException("Failed to schedule topology: " + topologyName);
    } else {
        // stop the server and close the state manager
        LOG.log(Level.INFO, "Shutting down topology: {0}", topologyName);
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) Properties(java.util.Properties) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 67 with Options

use of org.apache.commons.cli.Options in project heron by twitter.

the class MetricsCacheManager method constructHelpOptions.

// construct command line help options
private static Options constructHelpOptions() {
    Options options = new Options();
    Option help = Option.builder("h").desc("List all options and their description").longOpt("help").build();
    options.addOption(help);
    return options;
}
Also used : Options(org.apache.commons.cli.Options) HeronSocketOptions(com.twitter.heron.common.network.HeronSocketOptions) Option(org.apache.commons.cli.Option)

Example 68 with Options

use of org.apache.commons.cli.Options in project heron by twitter.

the class CppCheckstyle method main.

public static void main(String[] args) throws IOException {
    CommandLineParser parser = new DefaultParser();
    // create the Options
    Options options = new Options();
    options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file").desc("bazel extra action protobuf file").build());
    options.addOption(Option.builder("c").required(true).hasArg().longOpt("cpplint_file").desc("Executable cpplint file to invoke").build());
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        String extraActionFile = line.getOptionValue("f");
        String cpplintFile = line.getOptionValue("c");
        Collection<String> sourceFiles = getSourceFiles(extraActionFile);
        if (sourceFiles.size() == 0) {
            LOG.fine("No cpp files found by checkstyle");
            return;
        }
        LOG.fine(sourceFiles.size() + " cpp files found by checkstyle");
        // Create and run the command
        List<String> commandBuilder = new ArrayList<>();
        commandBuilder.add(cpplintFile);
        commandBuilder.add("--linelength=100");
        // TODO: https://github.com/twitter/heron/issues/466,
        // Remove "runtime/references" when we fix all non-const references in our codebase.
        // TODO: https://github.com/twitter/heron/issues/467,
        // Remove "runtime/threadsafe_fn" when we fix all non-threadsafe libc functions
        commandBuilder.add("--filter=-build/header_guard,-runtime/references,-runtime/threadsafe_fn");
        commandBuilder.addAll(sourceFiles);
        runLinter(commandBuilder);
    } catch (ParseException exp) {
        LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage()));
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java " + CLASSNAME, options);
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) ArrayList(java.util.ArrayList) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 69 with Options

use of org.apache.commons.cli.Options in project uPortal by Jasig.

the class PortalShell method getOptions.

protected static Options getOptions() {
    final Options options = new Options();
    options.addOption(new Option("s", "script", true, "Groovy script to execute in the uPortal Shell."));
    return options;
}
Also used : Options(org.apache.commons.cli.Options) Option(org.apache.commons.cli.Option)

Example 70 with Options

use of org.apache.commons.cli.Options in project zm-mailbox by Zimbra.

the class FixCalendarPriorityUtil method setupCommandLineOptions.

protected void setupCommandLineOptions() {
    super.setupCommandLineOptions();
    Options options = getOptions();
    Option accountOpt = new Option(O_ACCOUNT, "account", true, "account email addresses seperated by white space or \"all\" for all accounts");
    accountOpt.setArgs(Option.UNLIMITED_VALUES);
    options.addOption(accountOpt);
    options.addOption(new Option(null, O_SYNC, false, "run synchronously; default is asynchronous"));
    options.addOption(SoapCLI.OPT_AUTHTOKEN);
    options.addOption(SoapCLI.OPT_AUTHTOKENFILE);
}
Also used : Options(org.apache.commons.cli.Options) Option(org.apache.commons.cli.Option)

Aggregations

Options (org.apache.commons.cli.Options)1086 CommandLine (org.apache.commons.cli.CommandLine)557 CommandLineParser (org.apache.commons.cli.CommandLineParser)382 ParseException (org.apache.commons.cli.ParseException)341 Option (org.apache.commons.cli.Option)325 HelpFormatter (org.apache.commons.cli.HelpFormatter)275 GnuParser (org.apache.commons.cli.GnuParser)207 DefaultParser (org.apache.commons.cli.DefaultParser)166 Test (org.junit.Test)148 PosixParser (org.apache.commons.cli.PosixParser)135 IOException (java.io.IOException)118 File (java.io.File)97 OptionGroup (org.apache.commons.cli.OptionGroup)56 DMLScript (org.apache.sysml.api.DMLScript)56 Path (org.apache.hadoop.fs.Path)54 ArrayList (java.util.ArrayList)38 BasicParser (org.apache.commons.cli.BasicParser)36 Properties (java.util.Properties)33 Configuration (org.apache.hadoop.conf.Configuration)31 FileInputStream (java.io.FileInputStream)29