List of usage examples for org.apache.commons.cli CommandLine getOptionValue
public String getOptionValue(char opt, String defaultValue)
From source file:com.aerospike.examples.ldt.ttl.LdtExpire.java
public static void main(String[] args) throws AerospikeException { try {/*from www . ja v a 2 s .c o m*/ Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 127.0.0.1)"); 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."); options.addOption("d", "data", false, "Generate data."); 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; } LdtExpire as = new LdtExpire(host, port, namespace, set); as.registerUDF(); if (cl.hasOption("d")) { as.generateData(); } else { as.expire(); } } catch (Exception e) { log.error("Critical error", e); } }
From source file:com.uber.tchannel.ping.PingClient.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "host", true, "Server Host to connect to"); options.addOption("p", "port", true, "Server Port to connect to"); options.addOption("n", "requests", true, "Number of requests to make"); options.addOption("?", "help", false, "Usage"); HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("?")) { formatter.printHelp("PingClient", options, true); return;//from ww w . j a v a 2 s . com } String host = cmd.getOptionValue("h", "localhost"); int port = Integer.parseInt(cmd.getOptionValue("p", "8888")); int requests = Integer.parseInt(cmd.getOptionValue("n", "10000")); System.out.println(String.format("Connecting from client to server on port: %d", port)); new PingClient(host, port, requests).run(); System.out.println("Stopping Client..."); }
From source file:be.redlab.maven.yamlprops.create.YamlConvertCli.java
public static void main(String... args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); options.addOption(Option.builder("s").argName("source").desc("the source folder or file to convert") .longOpt("source").hasArg(true).build()); options.addOption(Option.builder("t").argName("target").desc("the target file to store in") .longOpt("target").hasArg(true).build()); options.addOption(Option.builder("h").desc("print help").build()); try {//from w w w .j a v a2 s .c om CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { formatter.printHelp("converter", options); } File source = new File(cmd.getOptionValue("s", System.getProperty("user.dir"))); String name = source.getName(); if (source.isDirectory()) { PropertiesToYamlConverter yamlConverter = new PropertiesToYamlConverter(); String[] ext = { "properties" }; Iterator<File> fileIterator = FileUtils.iterateFiles(source, ext, true); while (fileIterator.hasNext()) { File next = fileIterator.next(); System.out.println(next); String s = StringUtils.removeStart(next.getParentFile().getPath(), source.getPath()); System.out.println(s); String f = StringUtils.split(s, IOUtils.DIR_SEPARATOR)[0]; System.out.println("key = " + f); Properties p = new Properties(); try { p.load(new FileReader(next)); yamlConverter.addProperties(f, p); } catch (IOException e) { e.printStackTrace(); } } FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); yamlConverter.writeYaml(fileWriter); fileWriter.close(); } else { Properties p = new Properties(); p.load(new FileReader(source)); FileWriter fileWriter = new FileWriter( new File(source.getParentFile(), StringUtils.substringBeforeLast(name, ".") + ".yaml")); new PropertiesToYamlConverter().addProperties(name, p).writeYaml(fileWriter); fileWriter.close(); } } catch (ParseException e) { e.printStackTrace(); formatter.printHelp("converter", options); } }
From source file:di.uniba.it.tee2.wiki.Wikidump2Index.java
/** * language xml_dump output_dir encoding * * @param args the command line arguments *//*from w w w . java 2 s .c o m*/ public static void main(String[] args) { try { CommandLine cmd = cmdParser.parse(options, args); if (cmd.hasOption("l") && cmd.hasOption("d") && cmd.hasOption("o")) { encoding = cmd.getOptionValue("e", "UTF-8"); minTextLegth = Integer.parseInt(cmd.getOptionValue("m", "4000")); if (cmd.hasOption("p")) { pageLimit = Integer.parseInt(cmd.getOptionValue("p")); } Wikidump2Index builder = new Wikidump2Index(); builder.init(cmd.getOptionValue("l"), cmd.getOptionValue("o")); builder.build(cmd.getOptionValue("d"), cmd.getOptionValue("l")); } else { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Index Wikipedia dump (single thread)", options, true); } } catch (Exception ex) { Logger.getLogger(Wikidump2Index.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:net.bobah.mail.Dupes.java
public static void main(String[] args) throws Exception { installDefaultUncaughtExceptionHandler(log); final CommandLineParser parser = new PosixParser(); final Options options = new Options() .addOption("j", "threads", true, "number of parallel threads to use for analyzing") .addOption("hash", true, "hash function to use, possible values: " + Arrays.toString(Hashes.values())) .addOption("dir", true, "add directory to search"); final CommandLine cmdline = parser.parse(options, args); final int threads = Integer.valueOf( cmdline.getOptionValue("threads", String.valueOf(Runtime.getRuntime().availableProcessors()))); final HashFunction hash = Hashes.valueOf(cmdline.getOptionValue("hash", "adler32")).hashfunc; final File[] dirs = Collections2 .transform(Arrays.asList(cmdline.getOptionValues("dir")), new Function<String, File>() { @Override//from w ww .j a v a 2 s. c om public File apply(String from) { return new File(from); } }).toArray(new File[] {}); log.info("hash: {}, threads: {}, dirs: {} in total", hash, threads, dirs.length); try { new Dupes(threads, hash, dirs).run(); } finally { Utils.shutdownLogger(); } }
From source file:di.uniba.it.tee2.text.TextDirIndex.java
/** * language_0 starting_dir_1 output_dir_2 n_thread_3 * * @param args the command line arguments *//*from ww w . java 2 s . co m*/ public static void main(String[] args) { try { CommandLine cmd = cmdParser.parse(options, args); if (cmd.hasOption("l") && cmd.hasOption("i") && cmd.hasOption("o")) { int nt = Integer.parseInt(cmd.getOptionValue("n", "2")); TextDirIndex builder = new TextDirIndex(); builder.init(cmd.getOptionValue("l"), cmd.getOptionValue("o"), nt); builder.build(cmd.getOptionValue("l"), cmd.getOptionValue("i")); } else { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Index a directory", options, true); } } catch (Exception ex) { Logger.getLogger(TextDirIndex.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.aerospike.utility.SetDelete.java
public static void main(String[] args) throws ParseException { Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: localhost)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set to delete (default: test)"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); if (args.length == 0 || cl.hasOption("u")) { logUsage(options);//from www. j a v a 2 s.c o m return; } String host = cl.getOptionValue("h", "127.0.0.1"); String portString = cl.getOptionValue("p", "3000"); int port = Integer.parseInt(portString); String set = cl.getOptionValue("s", "test"); String namespace = cl.getOptionValue("n", "test"); log.info("Host: " + host); log.info("Port: " + port); log.info("Name space: " + namespace); log.info("Set: " + set); if (set == null) { log.error("You must specify a set"); return; } try { final AerospikeClient client = new AerospikeClient(host, port); ScanPolicy scanPolicy = new ScanPolicy(); scanPolicy.includeBinData = false; scanPolicy.concurrentNodes = true; scanPolicy.priority = Priority.HIGH; /* * scan the entire Set using scannAll(). This will scan each node * in the cluster and return the record Digest to the call back object */ client.scanAll(scanPolicy, namespace, set, new ScanCallback() { public void scanCallback(Key key, Record record) throws AerospikeException { /* * for each Digest returned, delete it using delete() */ if (client.delete(null, key)) count++; /* * after 25,000 records delete, return print the count. */ if (count % 25000 == 0) { log.info("Deleted " + count); } } }, new String[] {}); log.info("Deleted " + count + " records from set " + set); } catch (AerospikeException e) { int resultCode = e.getResultCode(); log.info(ResultCode.getResultString(resultCode)); log.debug("Error details: ", e); } }
From source file:com.aerospike.examples.TopTen.java
public static void main(String[] args) { try {/*w w w.ja v a 2 s . c o m*/ Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 127.0.0.1)"); 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."); options.addOption("l", "load", false, "Load data."); options.addOption("q", "query", false, "Aggregate with query."); options.addOption("a", "all", false, "Aggregate all using ScanAggregate."); options.addOption("S", "scan", false, "Scan all for testing."); 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); TopTen as = new TopTen(host, port, namespace, set); /* * Create index for query * Index creation only needs to be done once and can be done using AQL or ASCLI also */ IndexTask it = as.client.createIndex(null, as.namespace, as.set, "top-10", TIME_BIN, IndexType.NUMERIC); it.waitTillComplete(); /* * Register UDF module * Registration only needs to be done after a change in the UDF module. */ RegisterTask rt = as.client.register(null, "udf/leaderboard.lua", "leaderboard.lua", Language.LUA); rt.waitTillComplete(); if (cl.hasOption("l")) { as.populateData(); return; } else if (cl.hasOption("q")) { as.queryAggregate(); return; } else if (cl.hasOption("a")) { as.scanAggregate(); return; } else if (cl.hasOption("S")) { as.scanAll(); return; } else { logUsage(options); } } catch (Exception e) { log.error("Critical error", e); } }
From source file:di.uniba.it.tee2.wiki.Wikidump2IndexMT.java
/** * language xml_dump output_dir n_thread encoding * * @param args the command line arguments *//*from w w w. j a va 2s . c o m*/ public static void main(String[] args) { try { CommandLine cmd = cmdParser.parse(options, args); if (cmd.hasOption("l") && cmd.hasOption("d") && cmd.hasOption("o")) { encoding = cmd.getOptionValue("e", "UTF-8"); minTextLegth = Integer.parseInt(cmd.getOptionValue("m", "4000")); /*if (cmd.hasOption("p")) { pageLimit = Integer.parseInt(cmd.getOptionValue("p")); }*/ int nt = Integer.parseInt(cmd.getOptionValue("n", "2")); Wikidump2IndexMT builder = new Wikidump2IndexMT(); builder.init(cmd.getOptionValue("l"), cmd.getOptionValue("o"), nt); //attach a shutdown hook Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { try { Wikidump2IndexMT.tee.close(); } catch (Exception ex) { Logger.getLogger(Wikidump2IndexMT.class.getName()).log(Level.SEVERE, null, ex); } } })); builder.build(cmd.getOptionValue("d"), cmd.getOptionValue("l")); } else { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Index Wikipedia dump (multi threads)", options, true); } } catch (Exception ex) { Logger.getLogger(Wikidump2IndexMT.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.illinois.cs.cogcomp.datalessclassification.ta.W2VDatalessAnnotator.java
/** * @param args config: config file path testFile: Test File *//*from ww w . j ava 2s. co m*/ public static void main(String[] args) { CommandLine cmd = ESADatalessAnnotator.getCMDOpts(args); ResourceManager rm; try { String configFile = cmd.getOptionValue("config", "config/project.properties"); ResourceManager nonDefaultRm = new ResourceManager(configFile); rm = new W2VDatalessConfigurator().getConfig(nonDefaultRm); } catch (IOException e) { rm = new W2VDatalessConfigurator().getDefaultConfig(); } String testFile = cmd.getOptionValue("testFile", "data/graphicsTestDocument.txt"); StringBuilder sb = new StringBuilder(); String line; try (BufferedReader br = new BufferedReader(new FileReader(new File(testFile)))) { while ((line = br.readLine()) != null) { sb.append(line); sb.append(" "); } String text = sb.toString().trim(); TokenizerTextAnnotationBuilder taBuilder = new TokenizerTextAnnotationBuilder(new StatefulTokenizer()); TextAnnotation ta = taBuilder.createTextAnnotation(text); W2VDatalessAnnotator datalessAnnotator = new W2VDatalessAnnotator(rm); datalessAnnotator.addView(ta); List<Constituent> annots = ta.getView(ViewNames.DATALESS_W2V).getConstituents(); System.out.println("Predicted LabelIDs:"); for (Constituent annot : annots) { System.out.println(annot.getLabel()); } Map<String, String> labelNameMap = DatalessAnnotatorUtils .getLabelNameMap(rm.getString(DatalessConfigurator.LabelName_Path.key)); System.out.println("Predicted Labels:"); for (Constituent annot : annots) { System.out.println(labelNameMap.get(annot.getLabel())); } } catch (FileNotFoundException e) { e.printStackTrace(); logger.error("Test File not found at " + testFile + " ... exiting"); System.exit(-1); } catch (AnnotatorException e) { e.printStackTrace(); logger.error("Error Annotating the Test Document with the Dataless View ... exiting"); System.exit(-1); } catch (IOException e) { e.printStackTrace(); logger.error("IO Error while reading the test file ... exiting"); System.exit(-1); } }