List of usage examples for org.apache.commons.cli DefaultParser DefaultParser
DefaultParser
From source file:UploadUrlGenerator.java
public static void main(String[] args) throws Exception { Options opts = new Options(); opts.addOption(Option.builder().longOpt(ENDPOINT_OPTION).required().hasArg().argName("url") .desc("Sets the ECS S3 endpoint to use, e.g. https://ecs.company.com:9021").build()); opts.addOption(Option.builder().longOpt(ACCESS_KEY_OPTION).required().hasArg().argName("access-key") .desc("Sets the Access Key (user) to sign the request").build()); opts.addOption(Option.builder().longOpt(SECRET_KEY_OPTION).required().hasArg().argName("secret") .desc("Sets the secret key to sign the request").build()); opts.addOption(Option.builder().longOpt(BUCKET_OPTION).required().hasArg().argName("bucket-name") .desc("The bucket containing the object").build()); opts.addOption(Option.builder().longOpt(KEY_OPTION).required().hasArg().argName("object-key") .desc("The object name (key) to access with the URL").build()); opts.addOption(Option.builder().longOpt(EXPIRES_OPTION).hasArg().argName("minutes") .desc("Minutes from local time to expire the request. 1 day = 1440, 1 week=10080, " + "1 month (30 days)=43200, 1 year=525600. Defaults to 1 hour (60).") .build());//from w w w. java2 s . c o m opts.addOption(Option.builder().longOpt(VERB_OPTION).hasArg().argName("http-verb").type(HttpMethod.class) .desc("The HTTP verb that will be used with the URL (PUT, GET, etc). Defaults to GET.").build()); opts.addOption(Option.builder().longOpt(CONTENT_TYPE_OPTION).hasArg().argName("mimetype") .desc("Sets the Content-Type header (e.g. image/jpeg) that will be used with the request. " + "Must match exactly. Defaults to application/octet-stream for PUT/POST and " + "null for all others") .build()); DefaultParser dp = new DefaultParser(); CommandLine cmd = null; try { cmd = dp.parse(opts, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar UploadUrlGenerator-xxx.jar", opts, true); System.exit(255); } URI endpoint = URI.create(cmd.getOptionValue(ENDPOINT_OPTION)); String accessKey = cmd.getOptionValue(ACCESS_KEY_OPTION); String secretKey = cmd.getOptionValue(SECRET_KEY_OPTION); String bucket = cmd.getOptionValue(BUCKET_OPTION); String key = cmd.getOptionValue(KEY_OPTION); HttpMethod method = HttpMethod.GET; if (cmd.hasOption(VERB_OPTION)) { method = HttpMethod.valueOf(cmd.getOptionValue(VERB_OPTION).toUpperCase()); } int expiresMinutes = 60; if (cmd.hasOption(EXPIRES_OPTION)) { expiresMinutes = Integer.parseInt(cmd.getOptionValue(EXPIRES_OPTION)); } String contentType = null; if (method == HttpMethod.PUT || method == HttpMethod.POST) { contentType = "application/octet-stream"; } if (cmd.hasOption(CONTENT_TYPE_OPTION)) { contentType = cmd.getOptionValue(CONTENT_TYPE_OPTION); } BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration cc = new ClientConfiguration(); // Force use of v2 Signer. ECS does not support v4 signatures yet. cc.setSignerOverride("S3SignerType"); AmazonS3Client s3 = new AmazonS3Client(credentials, cc); s3.setEndpoint(endpoint.toString()); S3ClientOptions s3c = new S3ClientOptions(); s3c.setPathStyleAccess(true); s3.setS3ClientOptions(s3c); // Sign the URL Calendar c = Calendar.getInstance(); c.add(Calendar.MINUTE, expiresMinutes); GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, key).withExpiration(c.getTime()) .withMethod(method); if (contentType != null) { req = req.withContentType(contentType); } URL u = s3.generatePresignedUrl(req); System.out.printf("URL: %s\n", u.toURI().toASCIIString()); System.out.printf("HTTP Verb: %s\n", method); System.out.printf("Expires: %s\n", c.getTime()); System.out.println("To Upload with curl:"); StringBuilder sb = new StringBuilder(); sb.append("curl "); if (method != HttpMethod.GET) { sb.append("-X "); sb.append(method.toString()); sb.append(" "); } if (contentType != null) { sb.append("-H \"Content-Type: "); sb.append(contentType); sb.append("\" "); } if (method == HttpMethod.POST || method == HttpMethod.PUT) { sb.append("-T <filename> "); } sb.append("\""); sb.append(u.toURI().toASCIIString()); sb.append("\""); System.out.println(sb.toString()); System.exit(0); }
From source file:de.tudarmstadt.ukp.dkpro.argumentation.io.XmiFilePatternJsonStreamDumper.java
public static void main(final String[] args) throws ParseException, UIMAException, IOException { // TODO: It would be nice to be able to read from standard input but it // seems that ResourceCollectionReaderBase doesn't facilitate this final CommandLineParser parser = new DefaultParser(); final Options opts = Parameter.createOptions(); try {/* w ww .j a v a 2 s. com*/ final CommandLine commandLine = parser.parse(opts, args); final String sourceLocation = commandLine.getOptionValue(Parameter.SOURCE_LOCATION.paramName); LOG.info(String.format("Source location is \"%s\".", sourceLocation)); final String targetLocation = commandLine.getOptionValue(Parameter.TARGET_LOCATION.paramName); LOG.info(String.format("Target location is \"%s\".", targetLocation)); new XmiFilePatternJsonStreamDumper(JsonStreamDumpWriter.class, sourceLocation, targetLocation).call(); } catch (final ParseException e) { printHelp(opts); throw e; } }
From source file:net.librec.tool.driver.DataDriver.java
public static void main(String[] args) throws Exception { LibrecTool tool = new DataDriver(); Options options = new Options(); options.addOption("build", false, "build model"); options.addOption("load", false, "load model"); options.addOption("save", false, "save model"); options.addOption("conf", true, "the path of configuration file"); options.addOption("jobconf", true, "a specified key-value pair for configuration"); options.addOption("D", true, "a specified key-value pair for configuration"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("build")) { tool.run(args);/*from w ww . ja va2 s .c om*/ } else if (cmd.hasOption("load")) { ; } else if (cmd.hasOption("save")) { ; } }
From source file:com.act.biointerpretation.mechanisminspection.ReactionValidator.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/*www .j a va 2 s . c o m*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(ReactionDesalter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } NoSQLAPI api = new NoSQLAPI(cl.getOptionValue(OPTION_READ_DB), cl.getOptionValue(OPTION_READ_DB)); MechanisticValidator validator = new MechanisticValidator(api); validator.init(); Map<Integer, List<Ero>> results = validator .validateOneReaction(Long.parseLong(cl.getOptionValue(OPTION_RXN_ID))); if (results == null) { System.out.format("ERROR: validation results are null.\n"); } else if (results.size() == 0) { System.out.format("No matching EROs were found for the specified reaction.\n"); } else { for (Map.Entry<Integer, List<Ero>> entry : results.entrySet()) { List<String> eroIds = entry.getValue().stream().map(x -> x.getId().toString()) .collect(Collectors.toList()); System.out.format("%d: %s\n", entry.getKey(), StringUtils.join(eroIds, ", ")); } } }
From source file:com.yahoo.gondola.tsunami.Tsunami.java
public static void main(String[] args) throws Exception { PropertyConfigurator.configure("conf/log4j.properties"); config = new Config(new File("conf/gondola-tsunami.conf")); // Process command line arguments CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption("w", true, "Number of writers per member, default = " + numWriters); options.addOption("h", false, "help"); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("h")) { new HelpFormatter().printHelp("Tsunami Test", options); return;//ww w . j av a 2s . co m } if (commandLine.hasOption("w")) { numWriters = Integer.parseInt(commandLine.getOptionValue("w")); } new Tsunami(); }
From source file:com.act.biointerpretation.l2expansion.L2PredictionCorpusOperations.java
public static void main(String[] args) throws IOException { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/*w w w . j a va 2 s. co m*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { LOGGER.error("Argument parsing failed: %s", e.getMessage()); HELP_FORMATTER.printHelp(L2PredictionCorpusOperations.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(L2PredictionCorpusOperations.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption(OPTION_WRITE_PRODUCTS_AS_LIST_OF_INCHIS)) { L2PredictionCorpus corpus = L2PredictionCorpus.readPredictionsFromJsonFile( new File(cl.getOptionValue(OPTION_WRITE_PRODUCTS_AS_LIST_OF_INCHIS))); corpus.writePredictionsAsInchiList( new File(cl.getOptionValue(OPTION_WRITE_PRODUCTS_AS_LIST_OF_INCHIS))); } }
From source file:net.librec.tool.driver.RecDriver.java
public static void main(String[] args) throws Exception { LibrecTool tool = new RecDriver(); Options options = new Options(); options.addOption("build", false, "build model"); options.addOption("load", false, "load model"); options.addOption("save", false, "save model"); options.addOption("exec", false, "run job"); options.addOption("conf", true, "the path of configuration file"); options.addOption("jobconf", true, "a specified key-value pair for configuration"); options.addOption("D", true, "a specified key-value pair for configuration"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("build")) { ;/*from w ww .ja va 2 s . c o m*/ } else if (cmd.hasOption("load")) { ; } else if (cmd.hasOption("save")) { ; } else if (cmd.hasOption("exec")) { tool.run(args); } }
From source file:Inmemantlr.java
public static void main(String[] args) { LOGGER.info("Inmemantlr tool"); HelpFormatter hformatter = new HelpFormatter(); Options options = new Options(); // Binary arguments options.addOption("h", "print this message"); Option grmr = Option.builder().longOpt("grmrfiles").hasArgs().desc("comma-separated list of ANTLR files") .required(true).argName("grmrfiles").type(String.class).valueSeparator(',').build(); Option infiles = Option.builder().longOpt("infiles").hasArgs() .desc("comma-separated list of files to parse").required(true).argName("infiles").type(String.class) .valueSeparator(',').build(); Option utilfiles = Option.builder().longOpt("utilfiles").hasArgs() .desc("comma-separated list of utility files to be added for " + "compilation").required(false) .argName("utilfiles").type(String.class).valueSeparator(',').build(); Option odir = Option.builder().longOpt("outdir") .desc("output directory in which the dot files will be " + "created").required(false).hasArg(true) .argName("outdir").type(String.class).build(); options.addOption(infiles);/*from w w w. java2 s . c o m*/ options.addOption(grmr); options.addOption(utilfiles); options.addOption(odir); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.hasOption('h')) { hformatter.printHelp("java -jar inmemantlr.jar", options); System.exit(0); } } catch (ParseException e) { hformatter.printHelp("java -jar inmemantlr.jar", options); LOGGER.error(e.getMessage()); System.exit(-1); } // input files Set<File> ins = getFilesForOption(cmd, "infiles"); // grammar files Set<File> gs = getFilesForOption(cmd, "grmrfiles"); // utility files Set<File> uf = getFilesForOption(cmd, "utilfiles"); // output dir Set<File> od = getFilesForOption(cmd, "outdir"); if (od.size() > 1) { LOGGER.error("output directories must be less than or equal to 1"); System.exit(-1); } if (ins.size() <= 0) { LOGGER.error("no input files were specified"); System.exit(-1); } if (gs.size() <= 0) { LOGGER.error("no grammar files were specified"); System.exit(-1); } LOGGER.info("create generic parser"); GenericParser gp = null; try { gp = new GenericParser(gs.toArray(new File[gs.size()])); } catch (FileNotFoundException e) { LOGGER.error(e.getMessage()); System.exit(-1); } if (!uf.isEmpty()) { try { gp.addUtilityJavaFiles(uf.toArray(new String[uf.size()])); } catch (FileNotFoundException e) { LOGGER.error(e.getMessage()); System.exit(-1); } } LOGGER.info("create and add parse tree listener"); DefaultTreeListener dt = new DefaultTreeListener(); gp.setListener(dt); LOGGER.info("compile generic parser"); try { gp.compile(); } catch (CompilationException e) { LOGGER.error("cannot compile generic parser: {}", e.getMessage()); System.exit(-1); } String fpfx = ""; for (File of : od) { if (!of.exists() || !of.isDirectory()) { LOGGER.error("output directory does not exist or is not a " + "directory"); System.exit(-1); } fpfx = of.getAbsolutePath(); } Ast ast; for (File f : ins) { try { gp.parse(f); } catch (IllegalWorkflowException | FileNotFoundException e) { LOGGER.error(e.getMessage()); System.exit(-1); } ast = dt.getAst(); if (!fpfx.isEmpty()) { String of = fpfx + "/" + FilenameUtils.removeExtension(f.getName()) + ".dot"; LOGGER.info("write file {}", of); try { FileUtils.writeStringToFile(new File(of), ast.toDot(), "UTF-8"); } catch (IOException e) { LOGGER.error(e.getMessage()); System.exit(-1); } } else { LOGGER.info("Tree for {} \n {}", f.getName(), ast.toDot()); } } System.exit(0); }
From source file:com.act.biointerpretation.cofactorremoval.ReactionCofactorRemover.java
public static void main(String[] args) throws Exception { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());//from ww w . java 2 s. c om } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { System.err.format("Argument parsing failed: %s\n", e.getMessage()); HELP_FORMATTER.printHelp(LoadPlateCompositionIntoDB.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(ReactionDesalter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); return; } NoSQLAPI api = new NoSQLAPI(cl.getOptionValue(OPTION_READ_DB), cl.getOptionValue(OPTION_READ_DB)); CofactorRemover cofactorRemover = new CofactorRemover(api); cofactorRemover.init(); Pair<Reaction, Reaction> results = cofactorRemover .removeCofactorsFromOneReaction(Long.parseLong(cl.getOptionValue(OPTION_RXN_ID))); System.out.format("Reaction before processing:\n"); printReport(results.getLeft()); System.out.println(); System.out.format("Reaction after processing:\n"); printReport(results.getRight()); System.out.println(); }
From source file:de.zazaz.iot.bosch.indego.util.CmdLineTool.java
public static void main(String[] args) { Options options = new Options(); StringBuilder commandList = new StringBuilder(); for (DeviceCommand cmd : DeviceCommand.values()) { if (commandList.length() > 0) { commandList.append(", "); }/*from w w w . j av a 2s .c om*/ commandList.append(cmd.toString()); } options.addOption(Option // .builder() // .longOpt("base-url") // .desc("Sets the base URL of the web service") // .hasArg() // .build()); options.addOption(Option // .builder("u") // .longOpt("username") // .desc("The username for authentication (usually mail address)") // .required() // .hasArg() // .build()); options.addOption(Option // .builder("p") // .longOpt("password") // .desc("The password for authentication") // .required() // .hasArg() // .build()); options.addOption(Option // .builder("c") // .longOpt("command") // .desc(String.format("The command, which should be sent to the device (%s)", commandList)) // .hasArg() // .build()); options.addOption(Option // .builder("q") // .longOpt("query-status") // .desc("Queries the status of the device") // .build()); options.addOption(Option // .builder() // .longOpt("query-calendar") // .desc("Queries the calendar of the device") // .build()); options.addOption(Option // .builder("?") // .longOpt("help") // .desc("Prints this help") // .build()); CommandLineParser parser = new DefaultParser(); CommandLine cmds = null; try { cmds = parser.parse(options, args); } catch (ParseException ex) { System.err.println(ex.getMessage()); System.err.println(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CmdLineTool.class.getName(), options); System.exit(1); return; } if (cmds.hasOption("?")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CmdLineTool.class.getName(), options); return; } String baseUrl = cmds.getOptionValue("base-url"); String username = cmds.getOptionValue('u'); String password = cmds.getOptionValue('p'); String commandStr = cmds.getOptionValue('c'); boolean doQueryState = cmds.hasOption('q'); boolean doQueryCalendar = cmds.hasOption("query-calendar"); DeviceCommand command = null; if (commandStr != null) { try { command = DeviceCommand.valueOf(commandStr.toUpperCase()); } catch (IllegalArgumentException ex) { System.err.println("Unknown command: " + commandStr); System.exit(1); } } IndegoController controller = new IndegoController(baseUrl, username, password); try { System.out.println("Connecting to device"); controller.connect(); System.out.println(String.format("...Connection established. Device serial number is: %s", controller.getDeviceSerialNumber())); if (command != null) { System.out.println(String.format("Sending command (%s)...", command)); controller.sendCommand(command); System.out.println("...Command sent successfully!"); } if (doQueryState) { System.out.println("Querying device state"); DeviceStateInformation state = controller.getState(); printState(System.out, state); } if (doQueryCalendar) { System.out.println("Querying device calendar"); DeviceCalendar calendar = controller.getCalendar(); printCalendar(System.out, calendar); } } catch (IndegoException ex) { ex.printStackTrace(); System.exit(2); } finally { controller.disconnect(); } }