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);
}
}
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);
}
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();
}
}
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);
}
}
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);
}
}
Aggregations