List of usage examples for org.apache.commons.cli CommandLine getOptionValue
public String getOptionValue(char opt, String defaultValue)
From source file:ed.manager.Manager.java
public static void main(String args[]) throws Exception { HttpMonitor.setApplicationType("System Manager"); Options o = new Options(); o.addOption("v", "verbose", false, "Verbose"); o.addOption("c", "config", true, "config file for TextConfigApplicationFactory"); CommandLine cl = (new BasicParser()).parse(o, args); ApplicationFactory factory = null;/*w w w. j a v a 2 s . c om*/ if (cl.hasOption("config")) factory = new TextConfigApplicationFactory(new File(cl.getOptionValue("config", null))); else factory = new GridConfigApplicationFactory(); Manager m = new Manager(factory, cl.hasOption("v")); m.start(); m.join(); }
From source file:com.aerospike.examples.tweetaspike.Program.java
public static void main(String[] args) throws AerospikeException { try {/* www. jav a2 s .c o m*/ Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 12)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set (default: demo)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); String host = cl.getOptionValue("h", "127.0.0.1"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String namespace = cl.getOptionValue("n", "test"); String set = cl.getOptionValue("s", "demo"); log.debug("Host: " + host); log.debug("Port: " + port); log.debug("Namespace: " + namespace); log.debug("Set: " + set); @SuppressWarnings("unchecked") List<String> cmds = cl.getArgList(); if (cmds.size() == 0 && cl.hasOption("u")) { logUsage(options); return; } Program as = new Program(host, port, namespace, set); as.work(); } catch (Exception e) { log.error("Critical error", e); } }
From source file:ed.net.lb.LB.java
public static void main(String args[]) throws Exception { int verbose = 0; for (int i = 0; i < args.length; i++) { if (args[i].matches("\\-v+")) { verbose = args[i].length() - 1; args[i] = ""; }/*from w w w .j a v a2 s .c om*/ } Options o = new Options(); o.addOption("p", "port", true, "Port to Listen On"); o.addOption("v", "verbose", false, "Verbose"); o.addOption("mapfile", "m", true, "file from which to load mappings"); CommandLine cl = (new BasicParser()).parse(o, args); final int port = Integer.parseInt(cl.getOptionValue("p", "8080")); MappingFactory mf = null; if (cl.hasOption("m")) mf = new TextMapping.Factory(cl.getOptionValue("m", null)); else mf = new GridMapping.Factory(); System.out.println("10gen load balancer"); System.out.println("\t port \t " + port); System.out.println("\t verbose \t " + verbose); int retriesLeft = 2; HttpMonitor.setApplicationType("Load Balancer"); LB lb = null; while (retriesLeft-- > 0) { try { lb = new LB(port, mf, verbose); break; } catch (BindException be) { be.printStackTrace(); System.out.println("can't bind to port. going to try to kill old one"); HttpDownload.downloadToJS(new URL("http://127.0.0.1:" + port + "/~kill")); Thread.sleep(100); } } if (lb == null) { System.err.println("couldn't ever bind"); System.exit(-1); return; } lb.start(); lb.join(); System.exit(0); }
From source file:com.mozilla.bagheera.consumer.KafkaSequenceFileConsumer.java
public static void main(String[] args) { OptionFactory optFactory = OptionFactory.getInstance(); Options options = KafkaConsumer.getOptions(); options.addOption(optFactory.create("o", "output", true, "HDFS base path for output.")); options.addOption(optFactory.create("df", "dateformat", true, "Date format for the date subdirectories.")); options.addOption(optFactory.create("fs", "filesize", true, "Max file size for output files.")); options.addOption(/*from w ww . j av a 2 s. c o m*/ optFactory.create("b", "usebytes", false, "Use BytesWritable for value rather than Text.")); options.addOption(optFactory.create("ts", "addtimestamp", false, "Adds bagheera timestamp to the json")); CommandLineParser parser = new GnuParser(); ShutdownHook sh = ShutdownHook.getInstance(); try { // Parse command line options CommandLine cmd = parser.parse(options, args); final KafkaConsumer consumer = KafkaConsumer.fromOptions(cmd); sh.addFirst(consumer); // Create a sink for storing data SinkConfiguration sinkConfig = new SinkConfiguration(); sinkConfig.setString("hdfssink.hdfs.basedir.path", cmd.getOptionValue("output", "/bagheera")); sinkConfig.setString("hdfssink.hdfs.date.format", cmd.getOptionValue("dateformat", "yyyy-MM-dd")); sinkConfig.setLong("hdfssink.hdfs.max.filesize", Long.parseLong(cmd.getOptionValue("filesize", "536870912"))); sinkConfig.setBoolean("hdfssink.hdfs.usebytes", cmd.hasOption("usebytes")); sinkConfig.setBoolean("hdfssink.hdfs.addtimestamp", cmd.hasOption("addtimestamp")); KeyValueSinkFactory sinkFactory = KeyValueSinkFactory.getInstance(SequenceFileSink.class, sinkConfig); sh.addLast(sinkFactory); // Set the sink for consumer storage consumer.setSinkFactory(sinkFactory); // Initialize metrics collection, reporting, etc. final MetricsManager manager = MetricsManager.getDefaultMetricsManager(); prepareHealthChecks(); // Begin polling consumer.poll(); } catch (ParseException e) { LOG.error("Error parsing command line options", e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(KafkaSequenceFileConsumer.class.getName(), options); } catch (NumberFormatException e) { LOG.error("Failed to parse filesize option", e); } }
From source file:eu.interedition.collatex.http.Server.java
public static void main(String... args) { try {/*from w w w. jav a2 s . c o m*/ final CommandLine commandLine = new GnuParser().parse(OPTIONS, args); if (commandLine.hasOption("h")) { new HelpFormatter().printHelp("collatex-server [<options> ...]\n", OPTIONS); return; } final Collator collator = new Collator(Integer.parseInt(commandLine.getOptionValue("mpc", "2")), Integer.parseInt(commandLine.getOptionValue("mcs", "0")), commandLine.getOptionValue("dot", null)); final String staticPath = System.getProperty("collatex.static.path", ""); final HttpHandler httpHandler = staticPath.isEmpty() ? new CLStaticHttpHandler(Server.class.getClassLoader(), "/static/") { @Override protected void onMissingResource(Request request, Response response) throws Exception { collator.service(request, response); } } : new StaticHttpHandler(staticPath.replaceAll("/+$", "") + "/") { @Override protected void onMissingResource(Request request, Response response) throws Exception { collator.service(request, response); } }; final NetworkListener httpListener = new NetworkListener("http", "0.0.0.0", Integer.parseInt(commandLine.getOptionValue("p", "7369"))); final CompressionConfig compressionConfig = httpListener.getCompressionConfig(); compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON); compressionConfig.setCompressionMinSize(860); // http://webmasters.stackexchange.com/questions/31750/what-is-recommended-minimum-object-size-for-gzip-performance-benefits compressionConfig.setCompressableMimeTypes("application/javascript", "application/json", "application/xml", "text/css", "text/html", "text/javascript", "text/plain", "text/xml"); final HttpServer httpServer = new HttpServer(); httpServer.addListener(httpListener); httpServer.getServerConfiguration().addHttpHandler(httpHandler, commandLine.getOptionValue("cp", "").replaceAll("/+$", "") + "/*"); Runtime.getRuntime().addShutdownHook(new Thread(() -> { if (LOG.isLoggable(Level.INFO)) { LOG.info("Stopping HTTP server"); } httpServer.shutdown(); })); httpServer.start(); Thread.sleep(Long.MAX_VALUE); } catch (Throwable t) { LOG.log(Level.SEVERE, "Error while parsing command line", t); System.exit(1); } }
From source file:com.flaptor.indextank.storage.LogWriterServer.java
public static void main(String[] args) throws IOException, InterruptedException { // create the parser CommandLineParser parser = new PosixParser(); int port;/*from w ww . j av a 2 s . com*/ LogWriterServer server; try { // parse the command line arguments CommandLine line = parser.parse(getOptions(), args); if (line.hasOption("help")) { printHelp(getOptions(), null); System.exit(1); return; } String val = null; val = line.getOptionValue("port", null); if (null != val) { port = Integer.valueOf(val); } else { printHelp(getOptions(), "Must specify a server port"); System.exit(1); return; } String path = null; path = line.getOptionValue("path", null); if (null != path) { server = new LogWriterServer(new File(path), port); } else { server = new LogWriterServer(port); } } catch (ParseException exp) { printHelp(getOptions(), exp.getMessage()); System.exit(1); return; } server.start(); }
From source file:com.subakva.formicid.Main.java
public static void main(final String[] args) { Options options = new Options(); options.addOption("p", "projecthelp", false, "print project help information"); options.addOption("f", "file", true, "use given buildfile"); options.addOption("h", "help", false, "print this message"); options.addOption("d", "debug", false, "print debugging information"); options.addOption("v", "verbose", false, "be extra verbose"); options.addOption("q", "quiet", false, "be extra quiet"); CommandLine cli; try {/*from w w w .j a v a 2 s. c om*/ cli = new GnuParser().parse(options, args); } catch (ParseException e) { System.out.println("Error: " + e.getMessage()); new HelpFormatter().printHelp(CLI_SYNTAX, options); return; } String scriptName = cli.getOptionValue("f", "build.js"); if (cli.hasOption("h")) { new HelpFormatter().printHelp(CLI_SYNTAX, options); return; } else if (cli.hasOption("p")) { runScript(scriptName, "projecthelp", null); } else { runScript(scriptName, "build", cli); } }
From source file:com.flaptor.indextank.storage.IndexesLogServer.java
public static void main(String[] args) throws IOException, InterruptedException { // create the parser CommandLineParser parser = new PosixParser(); int readerPort, managerPort; try {/* w ww. ja v a 2 s .c o m*/ // parse the command line arguments CommandLine line = parser.parse(getOptions(), args); if (line.hasOption("help")) { printHelp(getOptions(), null); System.exit(1); return; } String val = null; val = line.getOptionValue("reader_port", null); if (null != val) { readerPort = Integer.valueOf(val); } else { printHelp(getOptions(), "Must specify a server port"); System.exit(1); return; } val = null; val = line.getOptionValue("manager_port", null); if (null != val) { managerPort = Integer.valueOf(val); } else { printHelp(getOptions(), "Must specify a server port"); System.exit(1); return; } } catch (ParseException exp) { printHelp(getOptions(), exp.getMessage()); System.exit(1); return; } new IndexesLogServer(readerPort, managerPort).start(); }
From source file:com.google.endpoints.examples.bookstore.BookstoreClient.java
public static void main(String[] args) throws Exception { Options options = createOptions();/*from w w w . j a v a 2s. c o m*/ CommandLineParser parser = new DefaultParser(); CommandLine params; try { params = parser.parse(options, args); } catch (ParseException e) { System.err.println("Invalid command line: " + e.getMessage()); printUsage(options); return; } String address = params.getOptionValue("bookstore", DEFAULT_ADDRESS); String apiKey = params.getOptionValue("api_key"); String authToken = params.getOptionValue("auth_token"); String operation = params.getOptionValue("operation", "list"); // Create gRPC stub. BookstoreGrpc.BookstoreBlockingStub bookstore = createBookstoreStub(address, apiKey, authToken); if ("list".equals(operation)) { listShelves(bookstore); } else if ("create".equals(operation)) { createShelf(bookstore); } else if ("enumerate".equals(operation)) { enumerate(bookstore); } }
From source file:com.picdrop.security.SecureStoreMain.java
static public void main(String[] args) throws ParseException, IOException, FileNotFoundException, NoSuchAlgorithmException, CertificateException, KeyStoreException, KeyStoreException, InterruptedException { CommandLineParser cliP = new DefaultParser(); Options ops = generateBasicOptions(); CommandLine cli = cliP.parse(ops, args); HelpFormatter hlp = new HelpFormatter(); SecureStore ss;/*from www .j a v a2 s. co m*/ String path = "."; try { if (cli.hasOption("help")) { hlp.printHelp("SecureStore", ops); System.exit(0); } if (cli.hasOption("keystore")) { path = cli.getOptionValue("keystore", "."); } if (cli.hasOption("create")) { ss = new SecureStore(path, false); ss.createKeyStore(); System.exit(0); } else { ss = new SecureStore(path, true); } if (cli.hasOption("list")) { Enumeration<String> en = ss.listAlias(); while (en.hasMoreElements()) { System.out.println(en.nextElement()); } System.exit(0); } if (cli.hasOption("store")) { ss.storeValue(cli.getOptionValues("store")[0], cli.getOptionValues("store")[1]); ss.writeStore(); System.exit(0); } if (cli.hasOption("clear")) { ss.deleteValue(cli.getOptionValue("clear")); ss.writeStore(); System.exit(0); } } finally { hlp.printHelp("SecureStore", ops); System.exit(0); } }