use of org.apache.commons.cli.PosixParser in project databus by linkedin.
the class DataGenerator method main.
public static void main(String[] args) throws IOException, UnknownTypeException {
// load and verify the options
CommandLineParser parser = new PosixParser();
Options opts = loadOptions();
CommandLine cmd = null;
try {
cmd = parser.parse(opts, args);
} catch (org.apache.commons.cli.ParseException parseEx) {
LOG.error("Invalid option");
printHelp(opts);
return;
}
// check for necessary options
String fileLoc = cmd.getOptionValue("schemaLocation");
if (fileLoc == null) {
LOG.error("schemaLocation not specified");
printHelp(opts);
}
//get string length and check if min is greater than 0
// Generate the record
File schemaFile = new File(fileLoc);
DataGenerator dataGenerator = new DataGenerator(schemaFile);
GenericRecord record = dataGenerator.generateRandomRecord();
if (cmd.hasOption(PRINT_AVRO_JSON_OPTNAME)) {
String outname = cmd.getOptionValue(PRINT_AVRO_JSON_OPTNAME);
OutputStream outs = System.out;
if (!outname.equals("-")) {
outs = new FileOutputStream(outname);
}
printAvroJson(record, outs);
if (!outname.equals("-")) {
outs.close();
}
} else {
DataGenerator.prettyPrint(record);
}
}
use of org.apache.commons.cli.PosixParser in project hbase by apache.
the class RESTServer method parseCommandLine.
private static void parseCommandLine(String[] args, RESTServlet servlet) {
Options options = new Options();
options.addOption("p", "port", true, "Port to bind to [default: " + DEFAULT_LISTEN_PORT + "]");
options.addOption("ro", "readonly", false, "Respond only to GET HTTP " + "method requests [default: false]");
options.addOption(null, "infoport", true, "Port for web UI");
CommandLine commandLine = null;
try {
commandLine = new PosixParser().parse(options, args);
} catch (ParseException e) {
LOG.error("Could not parse: ", e);
printUsageAndExit(options, -1);
}
// check for user-defined port setting, if so override the conf
if (commandLine != null && commandLine.hasOption("port")) {
String val = commandLine.getOptionValue("port");
servlet.getConfiguration().setInt("hbase.rest.port", Integer.parseInt(val));
if (LOG.isDebugEnabled()) {
LOG.debug("port set to " + val);
}
}
// check if server should only process GET requests, if so override the conf
if (commandLine != null && commandLine.hasOption("readonly")) {
servlet.getConfiguration().setBoolean("hbase.rest.readonly", true);
if (LOG.isDebugEnabled()) {
LOG.debug("readonly set to true");
}
}
// check for user-defined info server port setting, if so override the conf
if (commandLine != null && commandLine.hasOption("infoport")) {
String val = commandLine.getOptionValue("infoport");
servlet.getConfiguration().setInt("hbase.rest.info.port", Integer.parseInt(val));
if (LOG.isDebugEnabled()) {
LOG.debug("Web UI port set to " + val);
}
}
@SuppressWarnings("unchecked") List<String> remainingArgs = commandLine != null ? commandLine.getArgList() : new ArrayList<>();
if (remainingArgs.size() != 1) {
printUsageAndExit(options, 1);
}
String command = remainingArgs.get(0);
if ("start".equals(command)) {
// continue and start container
} else if ("stop".equals(command)) {
System.exit(1);
} else {
printUsageAndExit(options, 1);
}
}
use of org.apache.commons.cli.PosixParser in project glacier-cli by carlossg.
the class Glacier method main.
public static void main(String[] args) throws Exception {
options = commonOptions();
try {
CommandLineParser parser = new PosixParser();
CommandLine cmd = parser.parse(options, args);
List<String> arguments = Arrays.asList(cmd.getArgs());
if (cmd.hasOption("help")) {
usage();
// Not reached
}
if (arguments.isEmpty()) {
throw new GlacierCliException("Must provide at least one command.");
}
GlacierCliCommand command = GlacierCliCommand.get(arguments.get(0));
if (command == null) {
throw new GlacierCliException("Invalid command given: " + arguments.get(0));
}
String defaultPropertiesPath = System.getProperty("user.home") + "/AwsCredentials.properties";
String propertiesPath = cmd.getOptionValue("properties", defaultPropertiesPath);
File props = new File(propertiesPath);
AWSCredentials credentials = new PropertiesCredentials(props);
Glacier glacier = new Glacier(credentials, cmd.getOptionValue("region", "us-east-1"));
switch(command) {
// Archive commands
case UPLOAD:
if (arguments.size() < 3) {
throw new GlacierCliException("The upload command requires at least three parameters.");
}
for (String archive : arguments.subList(2, arguments.size())) {
glacier.upload(arguments.get(1), archive);
}
break;
case DELETE:
if (arguments.size() != 3) {
throw new GlacierCliException("The delete command requires exactly three parameters.");
}
glacier.delete(arguments.get(1), arguments.get(2));
break;
case DOWNLOAD:
if (arguments.size() != 4) {
throw new GlacierCliException("The download command requires exactly four parameters.");
}
glacier.download(arguments.get(1), arguments.get(2), arguments.get(3));
break;
// Vault commands
case CREATE_VAULT:
if (arguments.size() != 2) {
throw new GlacierCliException("The create-vault command requires exactly one parameter.");
}
glacier.createVault(arguments.get(1));
break;
case DELETE_VAULT:
if (arguments.size() != 2) {
throw new GlacierCliException("The delete-vault command requires exactly two parameters.");
}
glacier.deleteVault(arguments.get(1));
break;
case INVENTORY:
if (arguments.size() != 2) {
throw new GlacierCliException("The inventory command requires exactly two parameters.");
}
glacier.inventory(arguments.get(1), cmd.getOptionValue("topic", "glacier"), cmd.getOptionValue("queue", "glacier"), cmd.getOptionValue("file", "glacier.json"));
break;
case INFO:
if (arguments.size() != 2) {
throw new GlacierCliException("The info command requires exactly two parameters.");
}
glacier.info(arguments.get(1));
break;
case LIST:
glacier.list();
break;
}
} catch (GlacierCliException e) {
System.err.println("error: " + e.getMessage());
System.err.println();
usage();
} catch (UnrecognizedOptionException e) {
System.err.println("error: Invalid argument: " + e.getOption());
usage();
}
}
use of org.apache.commons.cli.PosixParser in project head by mifos.
the class DataSetUpgradeUtil method parseOptions.
public void parseOptions(String[] args) throws URISyntaxException {
// 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(DATA_SET_OPTION_NAME)) {
if (line.hasOption(DATA_DIRECTORY_OPTION_NAME)) {
fail("Specify either a data set (-f) or data directory (-a) but not both.");
}
dataSetName = line.getOptionValue(DATA_SET_OPTION_NAME);
} else if (line.hasOption(DATA_DIRECTORY_OPTION_NAME)) {
dataSetDirectoryName = line.getOptionValue(DATA_DIRECTORY_OPTION_NAME);
} else {
fail("Specify either a data set (-f) or data directory (-a)");
}
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);
}
if (line.hasOption(DATABASE_OPTION_NAME)) {
databaseName = line.getOptionValue(DATABASE_OPTION_NAME);
}
if (line.hasOption(SCHEMA_FILE_OPTION_NAME)) {
schemaFileName = line.getOptionValue(SCHEMA_FILE_OPTION_NAME);
File file = new File(schemaFileName);
if (!file.exists()) {
fail("Unable to find schema file: " + schemaFileName);
}
} else {
missingOption(schemaFileOption);
}
if (line.hasOption(PORT_OPTION_NAME)) {
port = line.getOptionValue(PORT_OPTION_NAME);
}
} catch (ParseException exp) {
fail("Parsing failed. Reason: " + exp.getMessage());
}
}
use of org.apache.commons.cli.PosixParser in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsDatabaseLoaderMain method parseCommandLineOptions.
private CommandLine parseCommandLineOptions(String[] args) {
try {
Options options = new Options();
buildOptions(options);
Parser parser = new PosixParser();
return parser.parse(options, args);
} catch (ParseException e) {
System.err.println(e.getMessage());
printUsage();
System.exit(-1);
return null;
}
}
Aggregations