List of usage examples for org.apache.commons.cli CommandLineParser parse
CommandLine parse(Options options, String[] arguments) throws ParseException;
From source file:info.jejking.opengeodb.neo4j.importer.ImporterRunner.java
/** * Runs the importer.// www. j av a 2 s . c o m * * <p> * Supply the following arguments: * </p> * <ol> * <li>path to the tab-delimited place file</li> * <li>path to the tab-delimited postal code file</li> * <li>path to the directory where the Graph DB is to be found/created</li> * </ol> * * @param args * as above * @throws IOException * @throws ParseException */ public static void main(String[] args) throws IOException, ParseException { initOptions(); CommandLineParser parser = new GnuParser(); CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("opengeodb2neo4j", options); } else { String placeFilePath = commandLine.getOptionValue("p"); String zipFilePath = commandLine.getOptionValue("z"); String neo4jDirPath = commandLine.getOptionValue("n"); Importer importer = new Importer(); importer.doImport(placeFilePath, zipFilePath, neo4jDirPath); } }
From source file:com.ctriposs.rest4j.tools.snapshot.gen.Rest4JSnapshotExporterCmdLineApp.java
/** * @param args rest4jexporter -sourcepath sourcepath -resourcepackages packagenames [-name api_name] [-outdir outdir] *//*from w w w. j a v a 2 s . c o m*/ public static void main(String[] args) { CommandLine cl = null; try { final CommandLineParser parser = new GnuParser(); cl = parser.parse(OPTIONS, args); } catch (ParseException e) { System.err.println("Invalid arguments: " + e.getMessage()); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "rest4jexporter -sourcepath sourcepath [-resourcepackages packagenames] [-resourceclasses classnames]" + "[-name api_name] [-outdir outdir]", OPTIONS); System.exit(0); } final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH); try { final Rest4JSnapshotExporter exporter = new Rest4JSnapshotExporter(); exporter.setResolverPath(resolverPath); exporter.export(cl.getOptionValue("name"), null, cl.getOptionValues("sourcepath"), cl.getOptionValues("resourcepackages"), cl.getOptionValues("resourceClasses"), cl.getOptionValue("outdir", ".")); } catch (Throwable e) { log.error("Error writing Snapshot files", e); System.out.println("Error writing Snapshot files:\n" + e); System.exit(1); } }
From source file:demos.Main.java
public static void main(String[] args) throws Exception { try {//from w ww. ja v a2 s . c om CommandLineParser parser = new PosixParser(); CommandLine cmdLine = parser.parse(getOptions(), args); int status = run(cmdLine); System.exit(status); } catch (ParseException e) { printUsage(); System.exit(STATUS_SHOW_USAGE); } }
From source file:cc.twittertools.index.ExtractTweetidsFromCollection.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory") .create(COLLECTION_OPTION)); CommandLine cmdline = null;//ww w.jav a2s .c o m CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(COLLECTION_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractTweetidsFromCollection.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } StatusStream stream = new JsonStatusCorpusReader(file); Status status; while ((status = stream.next()) != null) { System.out.println(status.getId() + "\t" + status.getScreenname()); } }
From source file:com.adobe.aem.demomachine.Base64Encoder.java
public static void main(String[] args) throws IOException { String value = null;/*from w w w. jav a2 s .c om*/ // Command line options for this tool Options options = new Options(); options.addOption("v", true, "Value"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("v")) { value = cmd.getOptionValue("v"); } if (value == null) { System.out.println("Command line parameters: -v value"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } byte[] encodedBytes = Base64.encodeBase64(value.getBytes()); System.out.println(new String(encodedBytes)); }
From source file:demo.learn.shiro.tool.PasswordEncryptionTool.java
/** * Main method.//from w w w . j a va 2s .co m * @param args Requires a plain text password. */ @SuppressWarnings("static-access") public static void main(String[] args) { String plainTextPassword = "root"; Option p = OptionBuilder.withArgName("password").hasArg().withDescription("plain text password") .isRequired(false).create('p'); Options options = new Options(); options.addOption(p); try { CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("p")) { plainTextPassword = cmd.getOptionValue("p"); } } catch (ParseException pe) { String cmdLineSyntax = "java -cp %CLASSPATH% demo.learn.shiro.tool.PasswordEncryptionTool"; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(cmdLineSyntax, options, false); return; } final RandomNumberGenerator rng = new SecureRandomNumberGenerator(); final ByteSource salt = rng.nextBytes(); final String saltBase64 = Base64.encodeToString(salt.getBytes()); final String hashedPasswordBase64 = new Sha256Hash(plainTextPassword, salt, S.HASH_ITER).toBase64(); System.out.print("-p " + plainTextPassword); System.out.print(" -h " + hashedPasswordBase64); System.out.println(" -s " + saltBase64); }
From source file:ca.uqam.mglunit.Runner.java
public static void main(String[] args) throws Exception { Runner runner = new Runner(); TestResultLogger logger = new TestResultLogger(); logger.setOutputStream(System.out); try {//from ww w.j a v a 2s . c o m CommandLineParser parser = new GnuParser(); CommandLine cli = parser.parse(cliOptions, args); if (cli.hasOption("help") || cli.getArgs().length == 0) printHelp(); else { configureLogger(logger, cli); runner.setTestResultLogger(logger); runner.setSpecificationClass(Class.forName(cli.getArgs()[0])); runner.run(); } } catch (ParseException ex) { printHelp(); } finally { logger.print(); } }
From source file:com.nexmo.client.examples.TestVoiceCall.java
public static void main(String[] argv) throws Exception { Options options = new Options().addOption("v", "Verbosity") .addOption("f", "from", true, "Phone number to call from") .addOption("t", "to", true, "Phone number to call") .addOption("h", "webhook", true, "URL to call for instructions"); CommandLineParser parser = new DefaultParser(); CommandLine cli;/*from w ww . j ava 2 s . c o m*/ try { cli = parser.parse(options, argv); } catch (ParseException exc) { System.err.println("Parsing failed: " + exc.getMessage()); System.exit(128); return; } Queue<String> args = new LinkedList<String>(cli.getArgList()); String from = cli.getOptionValue("f"); String to = cli.getOptionValue("t"); System.out.println("From: " + from); System.out.println("To: " + to); NexmoClient client = new NexmoClient(new JWTAuthMethod("951614e0-eec4-4087-a6b1-3f4c2f169cb0", FileSystems.getDefault().getPath("valid_application_key.pem"))); client.getVoiceClient().createCall( new Call(to, from, "https://nexmo-community.github.io/ncco-examples/first_call_talk.json")); }
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());//from 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:ezbake.thrift.VisibilityBase64Converter.java
public static void main(String[] args) { try {//from w w w.ja v a 2s. c om Options options = new Options(); options.addOption("d", "deserialize", false, "deserialize base64 visibility, if not present tool will serialize"); options.addOption("v", "visibility", true, "formalVisibility to serialize, or base64 encoded string to deserialize"); options.addOption("h", "help", false, "display usage info"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("thrift-visibility-converter", options); return; } String input = cmd.getOptionValue("v"); boolean deserialize = cmd.hasOption("d"); String output; if (deserialize) { if (input == null) { System.err.println("Cannot deserialize empty string"); System.exit(1); } output = ThriftUtils.deserializeFromBase64(Visibility.class, input).toString(); } else { Visibility visibility = new Visibility(); if (input == null) { input = "(empty visibility)"; } else { visibility.setFormalVisibility(input); } output = ThriftUtils.serializeToBase64(visibility); } String operation = deserialize ? "deserialize" : "serialize"; System.out.println("operation: " + operation); System.out.println("input: " + input); System.out.println("output: " + output); } catch (TException | ParseException e) { System.out.println("An error occurred: " + e.getMessage()); System.exit(1); } }