use of org.apache.commons.cli.ParseException in project cdap by caskdata.
the class FlowQueuePendingCorrector method parseArgs.
private static CommandLine parseArgs(String[] args) {
Options options = new Options();
options.addOption(createOption("n", "namespace", true, "namespace (optional, leave empty to correct all flowlets)", false));
options.addOption(createOption("a", "app", true, "app (optional, leave empty to correct all apps)", false));
options.addOption(createOption("f", "flow", true, "flow (optional, leave empty to correct all flows)", false));
options.addOption(createOption("p", "producer-flowlet", true, "producer flowlet (optional, leave empty to correct entire flow)", false));
options.addOption(createOption("c", "consumer-flowlet", true, "consumer flowlet (optional, leave empty to correct entire flow)", false));
options.addOption(createOption("q", "queue", true, "flowlet queue (optional, defaults to \"queue\")", false));
CommandLineParser parser = new BasicParser();
try {
return parser.parse(options, args);
} catch (ParseException e) {
System.out.println(e.getMessage());
HelpFormatter formatter = new HelpFormatter();
String argsFormat = "[--namespace <namespace> " + "[--app <app> " + "[--flow <flow> " + "[[--producer-flowlet <flowlet> " + "--consumer-flowlet <flowlet> " + "[--queue <queue>]]]]]]";
formatter.printHelp(argsFormat, options);
System.exit(0);
return null;
}
}
use of org.apache.commons.cli.ParseException in project com.revolsys.open by revolsys.
the class ProcessorPipelineTool method processArguments.
@SuppressWarnings("unchecked")
public boolean processArguments(final String[] args) {
try {
final CommandLineParser parser = new PosixParser();
this.commandLine = parser.parse(this.options, args);
final List<String> arguments = this.commandLine.getArgList();
final Option[] options = this.commandLine.getOptions();
for (final Option option : options) {
final String shortOpt = option.getOpt();
if (shortOpt != null && shortOpt.equals("D")) {
final String argument = arguments.remove(0);
final String[] values = argument.split("=");
System.setProperty(values[0], values[1]);
}
}
if (this.commandLine.hasOption(SOURCE_DIRECTORY_OPTION)) {
this.sourceDirectory = new File(this.commandLine.getOptionValue(SOURCE_DIRECTORY_OPTION));
if (!this.sourceDirectory.isDirectory()) {
System.err.println("Source directory '" + this.sourceDirectory.getAbsolutePath() + "' does not exist or is not a directory");
return false;
}
}
if (this.commandLine.hasOption(SOURCE_FILE_EXTENSION_OPTION)) {
this.sourceFileExtension = this.commandLine.getOptionValue(SOURCE_FILE_EXTENSION_OPTION);
}
if (this.commandLine.hasOption(OUTPUT_DIRECTORY_OPTION)) {
this.targetDirectory = new File(this.commandLine.getOptionValue(OUTPUT_DIRECTORY_OPTION));
if (!this.targetDirectory.isDirectory()) {
System.err.println("Target directory '" + this.targetDirectory.getAbsolutePath() + "' does not exist or is not a directory");
return false;
}
}
if (this.commandLine.hasOption(LOG_DIRECTORY_OPTION)) {
this.logDirectory = new File(this.commandLine.getOptionValue(LOG_DIRECTORY_OPTION));
if (!this.logDirectory.isDirectory()) {
System.err.println("Log directory '" + this.logDirectory.getAbsolutePath() + "' does not exist or is not a directory");
return false;
}
}
this.scriptFile = new File(this.commandLine.getOptionValue(SCRIPT_OPTION));
if (!this.scriptFile.exists()) {
System.err.println("The script '" + this.scriptFile + "' does not exist");
return false;
}
this.excludePattern = this.commandLine.getOptionValue(EXCLUDE_PATTERN_OPTION);
if (this.sourceDirectory != null) {
if (this.targetDirectory == null) {
System.err.println("A " + OUTPUT_DIRECTORY + " must be specified if " + SOURCE_DIRECTORY + " is specified");
return false;
}
if (this.sourceFileExtension == null) {
System.err.println("A " + SOURCE_FLE_EXTENSION + " must be specified if " + SOURCE_DIRECTORY + " is specified");
return false;
}
} else {
this.sourceFile = new File(arguments.get(0));
if (!this.sourceFile.exists()) {
System.err.println("The file '" + this.sourceFile + "' does not exist");
return false;
}
this.targetFile = new File(arguments.get(1));
// if (targetFile.isDirectory()) {
// targetFile = new File(targetFile, sourceFile.getName());
// }
}
return true;
} catch (final MissingOptionException e) {
System.err.println("Missing " + e.getMessage() + " argument");
return false;
} catch (final ParseException e) {
System.err.println("Unable to process command line arguments: " + e.getMessage());
return false;
}
}
use of org.apache.commons.cli.ParseException in project ANNIS by korpling.
the class AnnisAdminRunner method doExport.
private void doExport(List<String> commandArgs) {
Options options = new OptionBuilder().createOptions();
try {
CommandLineParser parser = new PosixParser();
CommandLine cmdLine = parser.parse(options, commandArgs.toArray(new String[commandArgs.size()]));
if (cmdLine.getArgs().length < 2) {
throw new ParseException("Needs two arguments: corpus name and output folder");
}
queryDao.exportCorpus(cmdLine.getArgs()[0], new File(cmdLine.getArgs()[1]));
} catch (ParseException ex) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("annis-admin.sh export CORPUS DIR ...", options);
}
}
use of org.apache.commons.cli.ParseException in project ANNIS by korpling.
the class AnnisAdminRunner method doInit.
private void doInit(List<String> commandArgs) {
Options options = new OptionBuilder().addParameter("h", "host", "database server host (defaults to localhost)").addLongParameter("port", "database server port").addRequiredParameter("d", "database", "name of the ANNIS database (REQUIRED)").addRequiredParameter("u", "user", "name of the ANNIS user (REQUIRED)").addRequiredParameter("p", "password", "password of the ANNIS suer (REQUIRED)").addParameter("D", "defaultdb", "name of the PostgreSQL default database (defaults to \"postgres\")").addParameter("U", "superuser", "name of a PostgreSQL super user (defaults to \"postgres\")").addParameter("P", "superpassword", "password of a PostgreSQL super user").addParameter("m", "migratecorpora", "Try to import the already existing corpora into the database. " + "You can set the root directory for corpus sources as an argument.").addToggle("s", "ssl", false, "if given use SSL for connecting to the database").addLongParameter("schema", "The PostgreSQL schema to use (defaults to \"public\"). " + "Only lowercase characters and digits are allowed in the schema name.").createOptions();
CommandLineParser parser = new PosixParser();
CommandLine cmdLine = null;
try {
cmdLine = parser.parse(options, commandArgs.toArray(new String[commandArgs.size()]));
// check for required flags
if (!cmdLine.hasOption("user") || !cmdLine.hasOption("database") || !cmdLine.hasOption("password")) {
throw new ParseException("required option is missing");
}
String host = cmdLine.getOptionValue("host", "localhost");
String port = cmdLine.getOptionValue("port", "5432");
String database = cmdLine.getOptionValue("database");
String user = cmdLine.getOptionValue("user");
String password = cmdLine.getOptionValue("password");
String defaultDatabase = cmdLine.getOptionValue("defaultdb", "postgres");
String superUser = cmdLine.getOptionValue("superuser", "postgres");
String superPassword = cmdLine.getOptionValue("superpassword");
boolean useSSL = cmdLine.hasOption("ssl");
String pgSchema = cmdLine.getOptionValue("schema", "public").toLowerCase().replaceAll("[^a-z0-9]", "_");
;
boolean migrateCorpora = cmdLine.hasOption("migratecorpora");
List<Map<String, Object>> existingCorpora = new LinkedList<>();
if (migrateCorpora) {
// get corpus list
try {
existingCorpora = corpusAdministration.listCorpusStats();
} catch (Exception ex) {
log.warn("Could not get existing corpus list for migration, migrating " + "the corpora will be disabled.", ex);
migrateCorpora = false;
}
}
corpusAdministration.initializeDatabase(host, port, database, user, password, defaultDatabase, superUser, superPassword, useSSL, pgSchema);
if (migrateCorpora && existingCorpora.size() > 0) {
doMigration(cmdLine.getOptionValue("migratecorpora"), existingCorpora);
}
} catch (ParseException e) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("annis-admin.sh init", options);
}
}
use of org.apache.commons.cli.ParseException in project oozie by apache.
the class ArgParser method parseCommandLineArguments.
boolean parseCommandLineArguments(String[] args) {
final CommandLineParser parser = new GnuParser();
final Options options = setupOptions();
try {
commandLine = parser.parse(options, args);
} catch (final ParseException pe) {
System.err.print("Error: " + pe.getMessage());
System.err.println();
final HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("DiagBundleCollectorDriver", "A tool that collects a diagnostic bundle of information from Oozie", options, "", true);
return false;
}
return true;
}
Aggregations