Search in sources :

Example 26 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project moco by dreamhead.

the class ShutdownArgs method parse.

public static ShutdownArgs parse(final String[] args) {
    try {
        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = parser.parse(createShutdownOptions(), args);
        return new ShutdownArgs(StartArgsParser.getPort(cmd.getOptionValue("s")));
    } catch (ParseException e) {
        throw new ParseArgException("fail to parse arguments", e);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 27 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project moco by dreamhead.

the class StartArgsParser method doParse.

private StartArgs doParse(final String[] args) throws ParseException {
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options(), args);
    return parseArgs(cmd);
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 28 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project groovy by apache.

the class Java2GroovyMain method main.

public static void main(String[] args) {
    try {
        Options options = new Options();
        CommandLineParser cliParser = new DefaultParser();
        CommandLine cli = cliParser.parse(options, args);
        String[] filenames = cli.getArgs();
        if (filenames.length == 0) {
            System.err.println("Needs at least one filename");
        }
        Java2GroovyProcessor.processFiles(Arrays.asList(filenames));
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 29 with DefaultParser

use of org.apache.commons.cli.DefaultParser in project groovy by apache.

the class FileSystemCompiler method commandLineCompile.

/**
     * Same as main(args) except that exceptions are thrown out instead of causing
     * the VM to exit and the lookup for .groovy files can be controlled
     */
public static void commandLineCompile(String[] args, boolean lookupUnnamedFiles) throws Exception {
    Options options = createCompilationOptions();
    CommandLineParser cliParser = new DefaultParser();
    CommandLine cli;
    cli = cliParser.parse(options, args);
    if (cli.hasOption('h')) {
        displayHelp(options);
        return;
    }
    if (cli.hasOption('v')) {
        displayVersion();
        return;
    }
    displayStackTraceOnError = cli.hasOption('e');
    CompilerConfiguration configuration = generateCompilerConfigurationFromOptions(cli);
    // Load the file name list
    String[] filenames = generateFileNamesFromOptions(cli);
    boolean fileNameErrors = filenames == null;
    if (!fileNameErrors && (filenames.length == 0)) {
        displayHelp(options);
        return;
    }
    fileNameErrors = fileNameErrors && !validateFiles(filenames);
    if (!fileNameErrors) {
        doCompilation(configuration, null, filenames, lookupUnnamedFiles);
    }
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) CommandLineParser(org.apache.commons.cli.CommandLineParser) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 30 with DefaultParser

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

the class JavaCheckstyle 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("hc").required(true).hasArg().longOpt("heron_checkstyle_config_file").desc("checkstyle config file").build());
    options.addOption(Option.builder("ac").required(true).hasArg().longOpt("apache_checkstyle_config_file").desc("checkstyle config file for imported source files").build());
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        String extraActionFile = line.getOptionValue("f");
        String configFile = line.getOptionValue("hc");
        String apacheConfigFile = line.getOptionValue("ac");
        // check heron source file style
        String[] heronSourceFiles = getHeronSourceFiles(extraActionFile);
        checkStyle(heronSourceFiles, configFile);
        // check other apache source file style
        String[] apacheSourceFiles = getApacheSourceFiles(extraActionFile);
        checkStyle(apacheSourceFiles, apacheConfigFile);
    } 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) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

CommandLine (org.apache.commons.cli.CommandLine)41 DefaultParser (org.apache.commons.cli.DefaultParser)41 CommandLineParser (org.apache.commons.cli.CommandLineParser)29 ParseException (org.apache.commons.cli.ParseException)28 Options (org.apache.commons.cli.Options)27 HelpFormatter (org.apache.commons.cli.HelpFormatter)13 Option (org.apache.commons.cli.Option)9 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 Config (com.twitter.heron.spi.common.Config)3 Path (java.nio.file.Path)3 Level (java.util.logging.Level)3 Topology (com.ibm.streamsx.topology.Topology)2 PackingException (com.twitter.heron.spi.packing.PackingException)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 PropertyKey (alluxio.PropertyKey)1