use of org.apache.commons.cli.BasicParser in project atlas by apache.
the class HiveMetaStoreBridge method main.
public static void main(String[] args) {
int exitCode = EXIT_CODE_FAILED;
try {
Options options = new Options();
options.addOption("d", "database", true, "Database name");
options.addOption("t", "table", true, "Table name");
options.addOption("f", "filename", true, "Filename");
options.addOption("failOnError", false, "failOnError");
CommandLine cmd = new BasicParser().parse(options, args);
boolean failOnError = cmd.hasOption("failOnError");
String databaseToImport = cmd.getOptionValue("d");
String tableToImport = cmd.getOptionValue("t");
String fileToImport = cmd.getOptionValue("f");
Configuration atlasConf = ApplicationProperties.get();
String[] atlasEndpoint = atlasConf.getStringArray(ATLAS_ENDPOINT);
if (atlasEndpoint == null || atlasEndpoint.length == 0) {
atlasEndpoint = new String[] { DEFAULT_ATLAS_URL };
}
final AtlasClientV2 atlasClientV2;
if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
String[] basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput();
atlasClientV2 = new AtlasClientV2(atlasEndpoint, basicAuthUsernamePassword);
} else {
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
atlasClientV2 = new AtlasClientV2(ugi, ugi.getShortUserName(), atlasEndpoint);
}
HiveMetaStoreBridge hiveMetaStoreBridge = new HiveMetaStoreBridge(atlasConf, new HiveConf(), atlasClientV2);
if (StringUtils.isNotEmpty(fileToImport)) {
File f = new File(fileToImport);
if (f.exists() && f.canRead()) {
BufferedReader br = new BufferedReader(new FileReader(f));
String line = null;
while ((line = br.readLine()) != null) {
String[] val = line.split(":");
if (ArrayUtils.isNotEmpty(val)) {
databaseToImport = val[0];
if (val.length > 1) {
tableToImport = val[1];
} else {
tableToImport = "";
}
hiveMetaStoreBridge.importHiveMetadata(databaseToImport, tableToImport, failOnError);
}
}
exitCode = EXIT_CODE_SUCCESS;
} else {
LOG.error("Failed to read the input file: " + fileToImport);
}
} else {
hiveMetaStoreBridge.importHiveMetadata(databaseToImport, tableToImport, failOnError);
}
exitCode = EXIT_CODE_SUCCESS;
} catch (ParseException e) {
LOG.error("Failed to parse arguments. Error: ", e.getMessage());
printUsage();
} catch (Exception e) {
LOG.error("Import failed", e);
}
System.exit(exitCode);
}
use of org.apache.commons.cli.BasicParser in project core by jcryptool.
the class CommandEvaluator method evaluate.
public CommandEvaluator.EvaluationResult evaluate(String commandString) throws ParseException {
if (commandString.contains("\n")) {
// $NON-NLS-1$
// $NON-NLS-1$
String[] splitCommandStrings = commandString.split("((\\r\\n)|(\r)|(\n))");
return evaluateMultiline(splitCommandStrings);
}
// $NON-NLS-1$
int commandEnd = commandString.indexOf(" ");
commandEnd = commandEnd > 0 ? commandEnd : commandString.length();
String commandName = commandString.substring(0, commandEnd);
String cleanCommandLine = commandString.trim();
// $NON-NLS-1$
String commandArgs = commandString.substring(commandEnd).trim();
// $NON-NLS-1$
StringBuilder result = new StringBuilder();
Command command = commands.get(commandName);
if (command != null) {
CommandLine commandLine = null;
if (isCallForShortHelp(cleanCommandLine)) {
result.append(HelpCommand.getShortHelpFor(commandName, command, cleanCommandLine));
} else if (isCallForDetailedHelp(cleanCommandLine)) {
result.append(HelpCommand.getDetailedHelpFor(commandName, command, cleanCommandLine));
} else
try {
String[] args = splitArgs(commandArgs);
BasicParser parser = new BasicParser();
commandLine = parser.parse(command.createOptions(), args);
command.execute(commandLine);
result.append(command.getResult());
} catch (IllegalCommandException e) {
result.append(e.getMessage());
} catch (RuntimeException e) {
result.append(Messages.CommandEvaluator_1);
result.append(e.getLocalizedMessage());
} catch (ParseException e) {
// TODO only if it is a "help anormality"
result.append(HelpCommand.getHelpForBadCommandCall(commandName, command, cleanCommandLine, e));
return new EvaluationResult(result.toString(), ResultType.ERROR_SYNTAX);
}
} else {
result.append(NLS.bind(Messages.CommandEvaluator_0, commandName));
}
return new EvaluationResult(result.toString(), ResultType.OK);
}
use of org.apache.commons.cli.BasicParser in project mm-dev by sbl-sdsc.
the class ArgLigandInteractions method getCommandLine.
private static CommandLine getCommandLine(String[] args) {
Options options = new Options();
options.addOption("h", "help", false, "help");
options.addOption("o", "output-path", true, "path to output file");
options.addOption("r", "resolution", true, "minimum resolution of structure");
options.addOption("d", "distance-cutoff", true, "maximum distance for interactions");
options.addOption("b", "b-factor-cutoff", true, "maximum normalized b-factor");
options.addOption("min", "min-interactions", true, "minimum number of interactions");
options.addOption("max", "max-interactions", true, "maximum number of interactions");
options.addOption("w", "include-waters", false, "include water-water interactions");
CommandLineParser parser = new BasicParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
System.out.println("ERROR: invalid command line arguments: " + e.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(ArgLigandInteractions.class.getSimpleName(), options);
System.exit(-1);
}
if (cmd.hasOption("help")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(ArgLigandInteractions.class.getSimpleName(), options);
System.exit(1);
}
return cmd;
}
use of org.apache.commons.cli.BasicParser in project eol-globi-data by jhpoelen.
the class NanoPress method main.
public static void main(final String[] args) throws IOException {
CommandLineParser parser = new BasicParser();
Options options = new Options();
Option inputOpt = new Option("i", "input", true, "location of neo4j db");
options.addOption(inputOpt);
inputOpt.setRequired(true);
Option outputOpt = new Option("o", "output", true, "output location for nanopubs");
options.addOption(outputOpt);
outputOpt.setRequired(true);
Option batchSize = new Option("b", "batchSize", true, "number of interaction to be indexed at once");
options.addOption(batchSize);
Option opt = new Option("n", "nanoOnly", false, "output location for nanopubs");
options.addOption(opt);
CommandLine cmdLine;
try {
cmdLine = parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(NanoPress.class.getSimpleName(), options);
System.exit(1);
return;
}
String inputFilePath = cmdLine.getOptionValue("input");
String outputFilePath = cmdLine.getOptionValue("output");
LOG.info("reading from neo4j: [" + inputFilePath + "], writing nanopubs to [" + outputFilePath + "]");
Map<String, String> config = MapUtil.stringMap("keep_logical_logs", "0M size", // , "cache_type", "none"
"dump_configuration", "true");
final GraphDatabaseService graphService = GraphService.getGraphService(inputFilePath, config);
File pubDir = new File(outputFilePath);
FileUtils.forceMkdir(pubDir);
createLinkers(cmdLine, graphService, pubDir).forEach(LinkUtil::doTimedLink);
}
use of org.apache.commons.cli.BasicParser in project jackrabbit by apache.
the class JcrClient method run.
/**
* Run client
* @param args
* the arguments
*/
private void run(String[] args) {
try {
// parse arguments
Parser parser = new BasicParser();
org.apache.commons.cli.CommandLine cl = parser.parse(options, args);
// Set locale
this.setLocale(cl);
// Welcome message
System.out.println(bundle.getString("word.welcome"));
// check interactive mode
if (cl.hasOption("source")) {
this.runNonInteractive(cl);
} else {
this.runInteractive();
}
} catch (Exception e) {
HelpFormatter hf = new HelpFormatter();
hf.printHelp("jcrclient", options);
e.printStackTrace();
return;
}
}
Aggregations