List of usage examples for org.apache.commons.cli CommandLineParser parse
CommandLine parse(Options options, String[] arguments) throws ParseException;
From source file:com.dattack.dbping.cli.PingAnalyzerCli.java
/** * The <code>main</code> method. * * @param args//from www .j a va 2 s. c o m * the program arguments */ public static void main(final String[] args) { try { // create Options object final Options options = new Options(); // add t option options.addOption(START_DATE_OPTION, true, "the date for an analysis run to begin"); options.addOption(END_DATE_OPTION, true, "the date for an analysis run to finish"); options.addOption(SPAN_OPTION, true, "the period of time between points"); options.addOption(DATA_FILE_OPTION, true, "the data file to analyze"); options.addOption(METRIC_OPTION, true, "the metric to analyze"); options.addOption(MAX_VALUE_OPTION, true, "the maximum value to use"); options.addOption(MIN_VALUE_OPTION, true, "the minimum value to use"); final CommandLineParser parser = new DefaultParser(); final CommandLine cmd = parser.parse(options, args); final ReportContext context = new ReportContext(); context.setStartDate(TimeUtils.parseDate(cmd.getOptionValue(START_DATE_OPTION))); context.setEndDate(TimeUtils.parseDate(cmd.getOptionValue(END_DATE_OPTION))); context.setTimeSpan(TimeUtils.parseTimeSpanMillis(cmd.getOptionValue(SPAN_OPTION))); context.setMaxValue(parseLong(cmd.getOptionValue(MAX_VALUE_OPTION))); context.setMinValue(parseLong(cmd.getOptionValue(MIN_VALUE_OPTION))); if (cmd.hasOption(METRIC_OPTION)) { for (final String metricName : cmd.getOptionValues(METRIC_OPTION)) { context.addMetricNameFilter(MetricName.parse(metricName)); } } final PingAnalyzerCli ping = new PingAnalyzerCli(); for (final String file : cmd.getOptionValues(DATA_FILE_OPTION)) { ping.execute(new File(file), context); } } catch (final ParseException | ConfigurationException e) { System.err.println(e.getMessage()); } }
From source file:com.dattack.dbtools.ping.PingAnalyzer.java
/** * The <code>main</code> method. * * @param args/*from w ww. jav a 2 s. c o m*/ * the program arguments */ public static void main(final String[] args) { try { // create Options object final Options options = new Options(); // add t option options.addOption(START_DATE_OPTION, true, "the date for an analysis run to begin"); options.addOption(END_DATE_OPTION, true, "the date for an analysis run to finish"); options.addOption(SPAN_OPTION, true, "the period of time between points"); options.addOption(DATA_FILE_OPTION, true, "the data file to analyze"); options.addOption(METRIC_OPTION, true, "the metric to analyze"); options.addOption(MAX_VALUE_OPTION, true, "the maximum value to use"); options.addOption(MIN_VALUE_OPTION, true, "the minimum value to use"); final CommandLineParser parser = new DefaultParser(); final CommandLine cmd = parser.parse(options, args); final ReportContext context = new ReportContext(); context.setStartDate(TimeUtils.parseDate(cmd.getOptionValue(START_DATE_OPTION))); context.setEndDate(TimeUtils.parseDate(cmd.getOptionValue(END_DATE_OPTION))); context.setTimeSpan(TimeUtils.parseTimeSpanMillis(cmd.getOptionValue(SPAN_OPTION))); context.setMaxValue(parseLong(cmd.getOptionValue(MAX_VALUE_OPTION))); context.setMinValue(parseLong(cmd.getOptionValue(MIN_VALUE_OPTION))); if (cmd.hasOption(METRIC_OPTION)) { for (final String metricName : cmd.getOptionValues(METRIC_OPTION)) { context.addMetricNameFilter(MetricName.parse(metricName)); } } final PingAnalyzer ping = new PingAnalyzer(); for (final String file : cmd.getOptionValues(DATA_FILE_OPTION)) { ping.execute(new File(file), context); } } catch (final ParseException | ConfigurationException e) { System.err.println(e.getMessage()); } }
From source file:com.genentech.chemistry.openEye.apps.SDFRingSystemExtractor.java
/** * @param args//from w w w.ja v a 2s .c o m */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported"); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported"); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); SDFRingSystemExtractor extractor = new SDFRingSystemExtractor(outFile); extractor.run(inFile); extractor.close(); }
From source file:com.hortonworks.registries.storage.tool.shell.ShellMigrationInitializer.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(Option.builder("s").numberOfArgs(1).longOpt(OPTION_SCRIPT_ROOT_PATH) .desc("Root directory of script path").build()); options.addOption(Option.builder("c").numberOfArgs(1).longOpt(OPTION_CONFIG_FILE_PATH) .desc("Config file path").build()); options.addOption(Option.builder().hasArg(false).longOpt(ShellMigrationOption.MIGRATE.toString()) .desc("Execute schema migration from last check point").build()); options.addOption(Option.builder().hasArg(false).longOpt(ShellMigrationOption.INFO.toString()) .desc("Show the status of the schema migration compared to the target database").build()); options.addOption(Option.builder().hasArg(false).longOpt(ShellMigrationOption.VALIDATE.toString()) .desc("Validate the target database changes with the migration scripts").build()); options.addOption(Option.builder().hasArg(false).longOpt(ShellMigrationOption.REPAIR.toString()).desc( "Repairs the SCRIPT_CHANGE_LOG by removing failed migrations and correcting checksum of existing migration script") .build());/* ww w.j a v a2 s . c om*/ CommandLineParser parser = new BasicParser(); CommandLine commandLine = parser.parse(options, args); if (!commandLine.hasOption(OPTION_SCRIPT_ROOT_PATH)) { usage(options); System.exit(1); } boolean isShellMigrationOptionSpecified = false; ShellMigrationOption shellMigrationOptionSpecified = null; for (ShellMigrationOption shellMigrationOption : ShellMigrationOption.values()) { if (commandLine.hasOption(shellMigrationOption.toString())) { if (isShellMigrationOptionSpecified) { System.out.println( "Only one operation can be execute at once, please select one of ',migrate', 'validate', 'info', 'repair'."); System.exit(1); } isShellMigrationOptionSpecified = true; shellMigrationOptionSpecified = shellMigrationOption; } } if (!isShellMigrationOptionSpecified) { System.out.println( "One of the option 'migrate', 'validate', 'info', 'repair' must be specified to execute."); System.exit(1); } String scriptRootPath = commandLine.getOptionValue(OPTION_SCRIPT_ROOT_PATH); String confFilePath = commandLine.getOptionValue(OPTION_CONFIG_FILE_PATH); StorageProviderConfiguration storageProperties; try { Map<String, Object> conf = Utils.readConfig(confFilePath); StorageProviderConfigurationReader confReader = new StorageProviderConfigurationReader(); storageProperties = confReader.readStorageConfig(conf); } catch (IOException e) { System.err.println("Error occurred while reading config file: " + confFilePath); System.exit(1); throw new IllegalStateException("Shouldn't reach here"); } ShellMigrationHelper schemaMigrationHelper = new ShellMigrationHelper( ShellFlywayFactory.get(storageProperties, scriptRootPath)); try { schemaMigrationHelper.execute(shellMigrationOptionSpecified); System.out.println(String.format("\"%s\" option successful", shellMigrationOptionSpecified.toString())); } catch (Exception e) { System.err.println(String.format("\"%s\" option failed : %s", shellMigrationOptionSpecified.toString(), e.getMessage())); System.exit(1); } }
From source file:com.mosso.client.cloudfiles.sample.FilesMakeContainer.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);// w w w . j ava2s . com CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); String containerName = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); createContaier(containerName); } //end if (line.hasOption("container")) else if (args.length > 0) { //If we got this far there are command line arguments but none of what we expected treat the first one as the Container name containerName = args[0]; createContaier(containerName); } else { System.err.println("You must provide the -container with a valid value for this to work !"); System.exit(-1); } } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (IOException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.cohesionforce.AvroToParquet.java
public static void main(String[] args) { String inputFile = null;/*w w w .j a v a 2 s. c o m*/ String outputFile = null; HelpFormatter formatter = new HelpFormatter(); // create Options object Options options = new Options(); // add t option options.addOption("i", true, "input avro file"); options.addOption("o", true, "ouptut Parquet file"); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); inputFile = cmd.getOptionValue("i"); if (inputFile == null) { formatter.printHelp("AvroToParquet", options); return; } outputFile = cmd.getOptionValue("o"); } catch (ParseException exc) { System.err.println("Problem with command line parameters: " + exc.getMessage()); return; } File avroFile = new File(inputFile); if (!avroFile.exists()) { System.err.println("Could not open file: " + inputFile); return; } try { DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(); DataFileReader<GenericRecord> dataFileReader; dataFileReader = new DataFileReader<GenericRecord>(avroFile, datumReader); Schema avroSchema = dataFileReader.getSchema(); // choose compression scheme CompressionCodecName compressionCodecName = CompressionCodecName.SNAPPY; // set Parquet file block size and page size values int blockSize = 256 * 1024 * 1024; int pageSize = 64 * 1024; String base = FilenameUtils.removeExtension(avroFile.getAbsolutePath()) + ".parquet"; if (outputFile != null) { File file = new File(outputFile); base = file.getAbsolutePath(); } Path outputPath = new Path("file:///" + base); // the ParquetWriter object that will consume Avro GenericRecords ParquetWriter<GenericRecord> parquetWriter; parquetWriter = new AvroParquetWriter<GenericRecord>(outputPath, avroSchema, compressionCodecName, blockSize, pageSize); for (GenericRecord record : dataFileReader) { parquetWriter.write(record); } dataFileReader.close(); parquetWriter.close(); } catch (IOException e) { System.err.println("Caught exception: " + e.getMessage()); } }
From source file:com.google.endpoints.examples.bookstore.BookstoreServer.java
public static void main(String[] args) throws Exception { Options options = createOptions();/* ww w .j av a 2 s. c o m*/ CommandLineParser parser = new DefaultParser(); CommandLine line; try { line = parser.parse(options, args); } catch (ParseException e) { System.err.println("Invalid command line: " + e.getMessage()); printUsage(options); return; } int port = DEFAULT_PORT; if (line.hasOption("port")) { String portOption = line.getOptionValue("port"); try { port = Integer.parseInt(portOption); } catch (java.lang.NumberFormatException e) { System.err.println("Invalid port number: " + portOption); printUsage(options); return; } } final BookstoreData data = initializeBookstoreData(); final BookstoreServer server = new BookstoreServer(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { System.out.println("Shutting down"); server.stop(); } catch (Exception e) { e.printStackTrace(); } } }); server.start(port, data); System.out.format("Bookstore service listening on %d\n", port); server.blockUntilShutdown(); }
From source file:com.rackspacecloud.client.cloudfiles.sample.FilesMakeContainer.java
public static void main(String args[]) throws NoSuchAlgorithmException, FilesException { //Build the command line options Options options = addCommandLineOptions(); if (args.length <= 0) printHelp(options);// w w w .ja va 2 s . c o m CommandLineParser parser = new GnuParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printHelp(options); String containerName = null; if (line.hasOption("container")) { containerName = line.getOptionValue("container"); createContaier(containerName); } //end if (line.hasOption("container")) else if (args.length > 0) { //If we got this far there are command line arguments but none of what we expected treat the first one as the Container name containerName = args[0]; createContaier(containerName); } else { System.err.println("You must provide the -container with a valid value for this to work !"); System.exit(-1); } } //end try catch (ParseException err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); err.printStackTrace(System.err); } //catch( ParseException err ) catch (Exception err) { System.err.println("Please see the logs for more details. Error Message: " + err.getMessage()); } //catch ( IOException err) }
From source file:com.spotify.cassandra.opstools.autobalance.Main.java
public static void main(String[] args) throws IOException, InterruptedException, ParseException { final Options options = new Options(); options.addOption("f", "force", false, "Force auto balance"); options.addOption("d", "dryrun", false, "Dry run"); options.addOption("r", "noresolve", false, "Don't resolve host names"); options.addOption("h", "host", true, "Host to connect to (default: localhost)"); options.addOption("p", "port", true, "Port to connect to (default: 7199)"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); new Main().run(cmd); }
From source file:eu.scape_project.pc.hadoop.TikaIdentifyHadoopJob.java
/** * The main entry point.//from w ww .jav a 2s .co m */ public static void main(String[] args) throws ParseException { Configuration conf = new Configuration(); GenericOptionsParser gop = new GenericOptionsParser(conf, args); HadoopJobCliConfig pc = new HadoopJobCliConfig(); CommandLineParser cmdParser = new PosixParser(); CommandLine cmd = cmdParser.parse(HadoopJobOptions.OPTIONS, gop.getRemainingArgs()); if ((args.length == 0) || (cmd.hasOption(HadoopJobOptions.HELP_OPT))) { HadoopJobOptions.exit("Usage", 0); } else { HadoopJobOptions.initOptions(cmd, pc); } String dir = pc.getDirStr(); String name = pc.getHadoopJobName(); if (name == null || name.equals("")) { name = "tika_identification"; } try { Job job = new Job(conf, name); // local debugging // job.getConfiguration().set("mapred.job.tracker", "local"); // job.getConfiguration().set("fs.default.name", "file:///"); job.setJarByClass(TikaIdentifyHadoopJob.class); job.setMapperClass(TikaIdentifyMapper.class); //job.setCombinerClass(TikaIdentifyReducer.class); job.setReducerClass(TikaIdentifyReducer.class); job.setInputFormatClass(TextInputFormat.class); job.setOutputFormatClass(TextOutputFormat.class); //SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.NONE); //conf.setMapOutputKeyClass(Text.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(LongWritable.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(LongWritable.class); SequenceFileInputFormat.addInputPath(job, new Path(dir)); String outpath = "output/" + System.currentTimeMillis() + "tid"; FileOutputFormat.setOutputPath(job, new Path(outpath)); job.waitForCompletion(true); System.out.print(outpath); System.exit(0); } catch (Exception e) { logger.error("I/O error", e); } }