use of org.apache.commons.cli.DefaultParser in project flink by apache.
the class FlinkYarnSessionCliTest method testDynamicProperties.
@Test
public void testDynamicProperties() throws IOException {
Map<String, String> map = new HashMap<String, String>(System.getenv());
File tmpFolder = tmp.newFolder();
File fakeConf = new File(tmpFolder, "flink-conf.yaml");
fakeConf.createNewFile();
map.put(ConfigConstants.ENV_FLINK_CONF_DIR, tmpFolder.getAbsolutePath());
TestBaseUtils.setEnv(map);
FlinkYarnSessionCli cli = new FlinkYarnSessionCli("", "", false);
Options options = new Options();
cli.addGeneralOptions(options);
cli.addRunOptions(options);
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, new String[] { "run", "-j", "fake.jar", "-n", "15", "-D", "akka.ask.timeout=5 min" });
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Parsing failed with " + e.getMessage());
}
AbstractYarnClusterDescriptor flinkYarnDescriptor = cli.createDescriptor(null, cmd);
Assert.assertNotNull(flinkYarnDescriptor);
Map<String, String> dynProperties = FlinkYarnSessionCli.getDynamicProperties(flinkYarnDescriptor.getDynamicPropertiesEncoded());
Assert.assertEquals(1, dynProperties.size());
Assert.assertEquals("5 min", dynProperties.get("akka.ask.timeout"));
}
use of org.apache.commons.cli.DefaultParser in project groovy by apache.
the class Groovyc method runCompiler.
private void runCompiler(String[] commandLine) {
// hand crank it so we can add our own compiler configuration
try {
Options options = FileSystemCompiler.createCompilationOptions();
CommandLineParser cliParser = new DefaultParser();
CommandLine cli;
cli = cliParser.parse(options, commandLine);
configuration = FileSystemCompiler.generateCompilerConfigurationFromOptions(cli);
configuration.setScriptExtensions(getScriptExtensions());
String tmpExtension = getScriptExtension();
if (tmpExtension.startsWith("*."))
tmpExtension = tmpExtension.substring(1);
configuration.setDefaultScriptExtension(tmpExtension);
// Load the file name list
String[] filenames = FileSystemCompiler.generateFileNamesFromOptions(cli);
boolean fileNameErrors = filenames == null;
fileNameErrors = fileNameErrors || !FileSystemCompiler.validateFiles(filenames);
if (targetBytecode != null) {
configuration.setTargetBytecode(targetBytecode);
}
if (!fileNameErrors) {
FileSystemCompiler.doCompilation(configuration, makeCompileUnit(), filenames, forceLookupUnnamedFiles);
}
} catch (Exception re) {
Throwable t = re;
if ((re.getClass() == RuntimeException.class) && (re.getCause() != null)) {
// unwrap to the real exception
t = re.getCause();
}
StringWriter writer = new StringWriter();
new ErrorReporter(t, false).write(new PrintWriter(writer));
String message = writer.toString();
taskSuccess = false;
if (errorProperty != null) {
getProject().setNewProperty(errorProperty, "true");
}
if (failOnError) {
log.error(message);
throw new BuildException("Compilation Failed", t, getLocation());
} else {
log.error(message);
}
}
}
use of org.apache.commons.cli.DefaultParser in project storm by apache.
the class StormSqlRunner method main.
public static void main(String[] args) throws Exception {
Options options = buildOptions();
CommandLineParser parser = new DefaultParser();
CommandLine commandLine = parser.parse(options, args);
if (!commandLine.hasOption(OPTION_SQL_FILE_LONG)) {
printUsageAndExit(options, OPTION_SQL_FILE_LONG + " is required");
}
String filePath = commandLine.getOptionValue(OPTION_SQL_FILE_LONG);
List<String> stmts = Files.readAllLines(Paths.get(filePath), StandardCharsets.UTF_8);
StormSql sql = StormSql.construct();
@SuppressWarnings("unchecked") Map<String, ?> conf = Utils.readStormConfig();
if (commandLine.hasOption(OPTION_SQL_EXPLAIN_LONG)) {
sql.explain(stmts);
} else if (commandLine.hasOption(OPTION_SQL_TOPOLOGY_NAME_LONG)) {
String topoName = commandLine.getOptionValue(OPTION_SQL_TOPOLOGY_NAME_LONG);
SubmitOptions submitOptions = new SubmitOptions(TopologyInitialStatus.ACTIVE);
sql.submit(topoName, stmts, conf, submitOptions, null, null);
} else {
printUsageAndExit(options, "Either " + OPTION_SQL_TOPOLOGY_NAME_LONG + " or " + OPTION_SQL_EXPLAIN_LONG + " must be presented");
}
}
use of org.apache.commons.cli.DefaultParser in project ProPPR by TeamCohen.
the class PropertiesConfigurationTest method testProperties.
@Test
public void testProperties() throws ParseException {
Options options = new Options();
options.addOption(OptionBuilder.withLongOpt("force").withDescription("Ignore errors and run anyway").create());
DefaultParser parser = new DefaultParser();
Properties props = new Properties();
// props.put("--force", true);
props.setProperty("--force", "true");
CommandLine line = parser.parse(options, new String[0], props);
assertTrue(line.hasOption("force"));
}
use of org.apache.commons.cli.DefaultParser in project sqflint by SkaceKamen.
the class SQFLint method main.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Options options = new Options();
CommandLineParser cmdParser = new DefaultParser();
CommandLine cmd;
options.addOption("j", "json", false, "output json");
options.addOption("v", "variables", false, "output variables info (only in json mode)");
options.addOption("e", "error", false, "stop on error");
options.addOption("nw", "no-warning", false, "skip warnings");
options.addOption("we", "warning-as-error", false, "output warnings as errors");
options.addOption("oc", "output-code", false, "output ERR return code when any error is encountered");
options.addOption("cp", "check-paths", false, "check for path existence for exevm and preprocessfile");
options.addOption("r", "root", true, "root for path checking (path to file is used if file is specified)");
options.addOption("h", "help", false, "");
options.addOption("iv", "ignore-variables", true, "ignored variables are treated as internal command");
options.addOption("s", "server", false, "run as server");
options.addOption("ip", "include-prefix", true, "adds include prefix override, format: prefix,path_to_use");
try {
cmd = cmdParser.parse(options, args);
} catch (org.apache.commons.cli.ParseException ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
return;
}
if (cmd.hasOption("h") || cmd.getArgs().length > 1) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("sqflint [OPTIONS] [FILE]", "Scans SQF file for errors and potential problems.", options, "Spaghetti");
return;
}
SQFPreprocessor preprocessor;
Linter linter;
String contents = null;
String root = null;
String[] ignoredVariables = new String[0];
if (cmd.hasOption("r")) {
root = cmd.getOptionValue("r");
}
if (cmd.hasOption("iv")) {
ignoredVariables = cmd.getOptionValues("iv");
}
cz.zipek.sqflint.linter.Options linterOptions;
try {
linterOptions = new cz.zipek.sqflint.linter.Options();
} catch (IOException ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
return;
}
if (cmd.hasOption("ip")) {
for (String value : cmd.getOptionValues("ip")) {
String[] split = value.split(",");
if (split.length != 2) {
System.out.println("Invalid include prefix : " + value);
System.out.println("Include prefix format is: prefix,include_path");
return;
}
linterOptions.getIncludePaths().put(split[0], split[1]);
}
}
linterOptions.setRootPath(root);
linterOptions.addIgnoredVariables(ignoredVariables);
if (cmd.hasOption("j")) {
linterOptions.setOutputFormatter(new JSONOutput());
}
linterOptions.setStopOnError(cmd.hasOption("e"));
linterOptions.setSkipWarnings(cmd.hasOption("nw"));
linterOptions.setOutputVariables(cmd.hasOption("v"));
linterOptions.setExitCodeEnabled(cmd.hasOption("oc"));
linterOptions.setWarningAsError(cmd.hasOption("we"));
linterOptions.setCheckPaths(cmd.hasOption("cp"));
preprocessor = new SQFPreprocessor(linterOptions);
if (!cmd.hasOption("s")) {
if (cmd.getArgs().length == 0) {
try {
String filename = null;
if (root != null) {
filename = Paths.get(root).resolve("file.sqf").toString();
}
contents = preprocessor.process(System.in, filename, false);
} catch (Exception ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
return;
}
} else if (cmd.getArgs().length == 1) {
String filename = cmd.getArgs()[0];
if (root == null) {
root = Paths.get(filename).toAbsolutePath().getParent().toString();
}
try {
contents = preprocessor.process(new java.io.FileInputStream(filename), filename, true);
} catch (Exception ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
return;
}
}
linterOptions.setRootPath(root);
if (contents != null) {
linter = new Linter(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)), linterOptions);
linter.setPreprocessor(preprocessor);
try {
System.exit(linter.start());
} catch (IOException ex) {
Logger.getLogger(SQFLint.class.getName()).log(Level.SEVERE, null, ex);
}
}
} else {
SQFLintServer server = new SQFLintServer(linterOptions);
server.start();
}
}
Aggregations