use of org.apache.commons.cli.PosixParser in project head by mifos.
the class PPITestDataGenerator method parseOptions.
public void parseOptions(String[] args) {
// create the command line parser
CommandLineParser parser = new PosixParser();
try {
// parse the command line arguments
CommandLine line = parser.parse(options, args);
if (line.hasOption(HELP_OPTION_NAME)) {
showHelp(options);
System.exit(0);
}
if (line.hasOption(TEST_DATA_FILE_OPTION_NAME)) {
if (line.hasOption(TEST_DATA_DIRECTORY_OPTION_NAME)) {
fail("Specify either a data set (-f) or data directory (-a) but not both.");
}
dataSetName = line.getOptionValue(TEST_DATA_FILE_OPTION_NAME);
} else if (line.hasOption(TEST_DATA_DIRECTORY_OPTION_NAME)) {
testDataDirectoryName = line.getOptionValue(TEST_DATA_DIRECTORY_OPTION_NAME);
} else {
fail("Specify either a data set (-f) or data directory (-a)");
}
if (line.hasOption(CLIENT_GLOBAL_ID_OPTION_NAME)) {
clientGlobalId = line.getOptionValue(CLIENT_GLOBAL_ID_OPTION_NAME);
} else {
missingOption(clientGlobalIdOption);
}
} catch (ParseException exp) {
fail("Parsing failed. Reason: " + exp.getMessage());
}
}
use of org.apache.commons.cli.PosixParser in project head by mifos.
the class DbUnitDataImportExport method parseOptions.
public void parseOptions(String[] args) {
// create the command line parser
CommandLineParser parser = new PosixParser();
try {
// parse the command line arguments
CommandLine line = parser.parse(options, args);
if (line.hasOption(HELP_OPTION_NAME)) {
showHelp(options);
System.exit(0);
}
if (line.hasOption(FILE_OPTION_NAME)) {
fileName = line.getOptionValue(FILE_OPTION_NAME);
}
if (line.hasOption(USER_OPTION_NAME)) {
user = line.getOptionValue(USER_OPTION_NAME);
} else {
missingOption(userOption);
}
if (line.hasOption(PASSWORD_OPTION_NAME)) {
password = line.getOptionValue(PASSWORD_OPTION_NAME);
} else {
missingOption(passwordOption);
}
if (line.hasOption(DATABASE_OPTION_NAME)) {
databaseName = line.getOptionValue(DATABASE_OPTION_NAME);
}
if (line.hasOption(IMPORT_OPTION_NAME)) {
doExport = false;
} else if (line.hasOption(EXPORT_OPTION_NAME)) {
doExport = true;
if (line.hasOption(SQL_OPTION_NAME)) {
exportAsSql = true;
}
}
} catch (ParseException exp) {
fail("Parsing failed. Reason: " + exp.getMessage());
}
}
use of org.apache.commons.cli.PosixParser in project Apktool by iBotPeaches.
the class Main method main.
public static void main(String[] args) throws IOException, InterruptedException, BrutException {
// set verbosity default
Verbosity verbosity = Verbosity.NORMAL;
// cli parser
CommandLineParser parser = new PosixParser();
CommandLine commandLine;
// load options
_Options();
try {
commandLine = parser.parse(allOptions, args, false);
} catch (ParseException ex) {
System.err.println(ex.getMessage());
usage();
return;
}
// check for verbose / quiet
if (commandLine.hasOption("-v") || commandLine.hasOption("--verbose")) {
verbosity = Verbosity.VERBOSE;
} else if (commandLine.hasOption("-q") || commandLine.hasOption("--quiet")) {
verbosity = Verbosity.QUIET;
}
setupLogging(verbosity);
// check for advance mode
if (commandLine.hasOption("advance") || commandLine.hasOption("advanced")) {
setAdvanceMode(true);
}
// @todo use new ability of apache-commons-cli to check hasOption for non-prefixed items
boolean cmdFound = false;
for (String opt : commandLine.getArgs()) {
if (opt.equalsIgnoreCase("d") || opt.equalsIgnoreCase("decode")) {
cmdDecode(commandLine);
cmdFound = true;
} else if (opt.equalsIgnoreCase("b") || opt.equalsIgnoreCase("build")) {
cmdBuild(commandLine);
cmdFound = true;
} else if (opt.equalsIgnoreCase("if") || opt.equalsIgnoreCase("install-framework")) {
cmdInstallFramework(commandLine);
cmdFound = true;
} else if (opt.equalsIgnoreCase("empty-framework-dir")) {
cmdEmptyFrameworkDirectory(commandLine);
cmdFound = true;
} else if (opt.equalsIgnoreCase("publicize-resources")) {
cmdPublicizeResources(commandLine);
cmdFound = true;
}
}
// if no commands ran, run the version / usage check.
if (cmdFound == false) {
if (commandLine.hasOption("version")) {
_version();
} else {
usage();
}
}
}
use of org.apache.commons.cli.PosixParser in project hadoop by apache.
the class TimelineSchemaCreator method parseArgs.
/**
* Parse command-line arguments.
*
* @param args
* command line arguments passed to program.
* @return parsed command line.
* @throws ParseException
*/
private static CommandLine parseArgs(String[] args) throws ParseException {
Options options = new Options();
// Input
Option o = new Option(ENTITY_TABLE_NAME_SHORT, "entityTableName", true, "entity table name");
o.setArgName("entityTableName");
o.setRequired(false);
options.addOption(o);
o = new Option(TTL_OPTION_SHORT, "metricsTTL", true, "TTL for metrics column family");
o.setArgName("metricsTTL");
o.setRequired(false);
options.addOption(o);
o = new Option(APP_TO_FLOW_TABLE_NAME_SHORT, "appToflowTableName", true, "app to flow table name");
o.setArgName("appToflowTableName");
o.setRequired(false);
options.addOption(o);
o = new Option(APP_TABLE_NAME_SHORT, "applicationTableName", true, "application table name");
o.setArgName("applicationTableName");
o.setRequired(false);
options.addOption(o);
// Options without an argument
// No need to set arg name since we do not need an argument here
o = new Option(SKIP_EXISTING_TABLE_OPTION_SHORT, "skipExistingTable", false, "skip existing Hbase tables and continue to create new tables");
o.setRequired(false);
options.addOption(o);
CommandLineParser parser = new PosixParser();
CommandLine commandLine = null;
try {
commandLine = parser.parse(options, args);
} catch (Exception e) {
LOG.error("ERROR: " + e.getMessage() + "\n");
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp(NAME + " ", options, true);
System.exit(-1);
}
return commandLine;
}
use of org.apache.commons.cli.PosixParser in project hadoop by apache.
the class ArgumentParser method parse.
/**
* Parses the command line options
*
* @return false if need to print help output
*
* @throws Exception
* when parsing fails
*/
ParsedOutput parse() throws Exception {
if (parsed == null) {
PosixParser parser = new PosixParser();
CommandLine popts = parser.parse(getOptionList(), argumentList, true);
if (popts.hasOption(ConfigOption.HELP.getOpt())) {
parsed = new ParsedOutput(null, this, true);
} else {
parsed = new ParsedOutput(popts, this, false);
}
}
return parsed;
}
Aggregations