List of usage examples for org.apache.commons.cli CommandLine getOptionValue
public String getOptionValue(char opt)
From source file:com.opengamma.integration.marketdata.WatchListRecorder.java
/** * Main entry point./* w w w .j a v a2s .c o m*/ * * @param args the arguments * @throws Exception if an error occurs */ public static void main(final String[] args) throws Exception { // CSIGNORE final CommandLineParser parser = new PosixParser(); final Options options = new Options(); final Option outputFileOpt = new Option("o", "output", true, "output file"); outputFileOpt.setRequired(true); options.addOption(outputFileOpt); final Option urlOpt = new Option("u", "url", true, "server url"); options.addOption(urlOpt); String outputFile = "watchList.txt"; String url = "http://localhost:8080/jax"; try { final CommandLine cmd = parser.parse(options, args); outputFile = cmd.getOptionValue("output"); url = cmd.getOptionValue("url"); } catch (final ParseException exp) { s_logger.error("Option parsing failed: {}", exp.getMessage()); System.exit(0); } final WatchListRecorder recorder = create(URI.create(url), "main", "combined"); recorder.addWatchScheme(ExternalSchemes.BLOOMBERG_TICKER); recorder.addWatchScheme(ExternalSchemes.BLOOMBERG_BUID); final PrintWriter pw = new PrintWriter(outputFile); recorder.setPrintWriter(pw); recorder.run(); pw.close(); System.exit(0); }
From source file:edu.cmu.lti.oaqa.apps.Client.java
public static void main(String args[]) { BufferedReader inp = new BufferedReader(new InputStreamReader(System.in)); Options opt = new Options(); Option o = new Option(PORT_SHORT_PARAM, PORT_LONG_PARAM, true, PORT_DESC); o.setRequired(true);//from w ww .ja v a 2s .co m opt.addOption(o); o = new Option(HOST_SHORT_PARAM, HOST_LONG_PARAM, true, HOST_DESC); o.setRequired(true); opt.addOption(o); opt.addOption(K_SHORT_PARAM, K_LONG_PARAM, true, K_DESC); opt.addOption(R_SHORT_PARAM, R_LONG_PARAM, true, R_DESC); opt.addOption(QUERY_TIME_SHORT_PARAM, QUERY_TIME_LONG_PARAM, true, QUERY_TIME_DESC); opt.addOption(RET_OBJ_SHORT_PARAM, RET_OBJ_LONG_PARAM, false, RET_OBJ_DESC); opt.addOption(RET_EXTERN_ID_SHORT_PARAM, RET_EXTERN_ID_LONG_PARAM, false, RET_EXTERN_ID_DESC); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try { CommandLine cmd = parser.parse(opt, args); String host = cmd.getOptionValue(HOST_SHORT_PARAM); String tmp = null; tmp = cmd.getOptionValue(PORT_SHORT_PARAM); int port = -1; try { port = Integer.parseInt(tmp); } catch (NumberFormatException e) { Usage("Port should be integer!"); } boolean retObj = cmd.hasOption(RET_OBJ_SHORT_PARAM); boolean retExternId = cmd.hasOption(RET_EXTERN_ID_SHORT_PARAM); String queryTimeParams = cmd.getOptionValue(QUERY_TIME_SHORT_PARAM); if (null == queryTimeParams) queryTimeParams = ""; SearchType searchType = SearchType.kKNNSearch; int k = 0; double r = 0; if (cmd.hasOption(K_SHORT_PARAM)) { if (cmd.hasOption(R_SHORT_PARAM)) { Usage("Range search is not allowed if the KNN search is specified!"); } tmp = cmd.getOptionValue(K_SHORT_PARAM); try { k = Integer.parseInt(tmp); } catch (NumberFormatException e) { Usage("K should be integer!"); } searchType = SearchType.kKNNSearch; } else if (cmd.hasOption(R_SHORT_PARAM)) { if (cmd.hasOption(K_SHORT_PARAM)) { Usage("KNN search is not allowed if the range search is specified!"); } searchType = SearchType.kRangeSearch; tmp = cmd.getOptionValue(R_SHORT_PARAM); try { r = Double.parseDouble(tmp); } catch (NumberFormatException e) { Usage("The range value should be numeric!"); } } else { Usage("One has to specify either range or KNN-search parameter"); } String separator = System.getProperty("line.separator"); StringBuffer sb = new StringBuffer(); String s; while ((s = inp.readLine()) != null) { sb.append(s); sb.append(separator); } String queryObj = sb.toString(); try { TTransport transport = new TSocket(host, port); transport.open(); TProtocol protocol = new TBinaryProtocol(transport); QueryService.Client client = new QueryService.Client(protocol); if (!queryTimeParams.isEmpty()) client.setQueryTimeParams(queryTimeParams); List<ReplyEntry> res = null; long t1 = System.nanoTime(); if (searchType == SearchType.kKNNSearch) { System.out.println(String.format("Running a %d-NN search", k)); res = client.knnQuery(k, queryObj, retExternId, retObj); } else { System.out.println(String.format("Running a range search (r=%g)", r)); res = client.rangeQuery(r, queryObj, retExternId, retObj); } long t2 = System.nanoTime(); System.out.println(String.format("Finished in %g ms", (t2 - t1) / 1e6)); for (ReplyEntry e : res) { System.out.println(String.format("id=%d dist=%g %s", e.getId(), e.getDist(), retExternId ? "externId=" + e.getExternId() : "")); if (retObj) System.out.println(e.getObj()); } transport.close(); // Close transport/socket ! } catch (TException te) { System.err.println("Apache Thrift exception: " + te); te.printStackTrace(); } } catch (ParseException e) { Usage("Cannot parse arguments"); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
From source file:backtype.storm.command.gray_upgrade.java
public static void main(String[] args) throws Exception { if (args == null || args.length < 1) { System.out.println("Invalid parameter"); usage();/*from ww w . j a v a 2 s. c o m*/ return; } String topologyName = args[0]; String[] str2 = Arrays.copyOfRange(args, 1, args.length); CommandLineParser parser = new GnuParser(); Options r = buildGeneralOptions(new Options()); CommandLine commandLine = parser.parse(r, str2, true); int workerNum = 0; String component = null; List<String> workers = null; if (commandLine.hasOption("n")) { workerNum = Integer.valueOf(commandLine.getOptionValue("n")); } if (commandLine.hasOption("p")) { component = commandLine.getOptionValue("p"); } if (commandLine.hasOption("w")) { String w = commandLine.getOptionValue("w"); if (!StringUtils.isBlank(w)) { workers = Lists.newArrayList(); String[] parts = w.split(","); for (String part : parts) { if (part.split(":").length == 2) { workers.add(part.trim()); } } } } upgradeTopology(topologyName, component, workers, workerNum); }
From source file:com.jones_systems.Tieout.java
public static void main(String[] args) { String testFilename = null;// www .j a v a2 s.co m Options options = new Options(); //options.addOption("f", "filename", true, "the file to use for the Tieout check"); Option filename = OptionBuilder.withArgName("filename").hasArg() .withDescription("the file name of the XML test file").create("filename"); options.addOption(filename); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("filename")) { testFilename = line.getOptionValue("filename"); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("tieout", options); System.exit(2); } } catch (ParseException exp) { } File testfile = new File(testFilename); if (!testfile.exists()) { System.err.println("Cannot find file!"); System.exit(1); } System.out.println("Starting test with file: " + testFilename); Tieout ts = new Tieout(testfile); boolean connected = ts.connectDatasources(); if (!connected) { System.err.print("Could not connect to all datasources"); System.exit(1); } ts.runTests(); }
From source file:com.google.cloud.runtimes.builder.Application.java
/** * Main method for invocation from the command line. Handles parsing of command line options. *///from w ww.j a va 2 s .c o m public static void main(String[] args) throws BuildStepException, IOException { addCliOptions(CLI_OPTIONS); CommandLine cmd = parse(args); String[] jdkMappings = cmd.getOptionValues("j"); String[] serverMappings = cmd.getOptionValues("s"); String compatImage = cmd.getOptionValue("c"); String mavenImage = cmd.getOptionValue("m"); String gradleImage = cmd.getOptionValue("g"); boolean disableSourceBuild = cmd.hasOption("n"); Injector injector = Guice .createInjector(new RootModule(mergeSettingsWithDefaults(jdkMappings, serverMappings), compatImage == null ? DEFAULT_COMPAT_RUNTIME_IMAGE : compatImage, mavenImage == null ? DEFAULT_MAVEN_DOCKER_IMAGE : mavenImage, gradleImage == null ? DEFAULT_GRADLE_DOCKER_IMAGE : gradleImage, disableSourceBuild, getAppYamlOverrideSettings(cmd))); // Perform dependency injection and run the application Path workspaceDir = Paths.get(System.getProperty("user.dir")); injector.getInstance(BuildPipelineConfigurator.class).generateDockerResources(workspaceDir); }
From source file:io.yucca.lucene.IndexUtility.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); initOptions(options);//from w w w . j a va 2 s . co m try { final CommandLine line = parser.parse(options, args); if (line.hasOption('h')) { usage(options); } if (line.hasOption('s')) { String value = line.getOptionValue('s'); sourceIndexDirectory = new File(value); if (sourceIndexDirectory.exists() == false) { log.error("Index source directory: {} does not exist!", sourceIndexDirectory); System.exit(1); } } else { usage(options); System.exit(1); } if (line.hasOption('d')) { String value = line.getOptionValue('d'); destIndexDirectory = new File(value); if (destIndexDirectory.exists() == true) { log.error("Index destination directory: {} already exist", destIndexDirectory); System.exit(1); } } else { usage(options); System.exit(1); } if (line.hasOption('v')) { try { String value = line.getOptionValue('v'); version = Version.parseLeniently(value); } catch (Exception e) { log.error("Unrecognized index version, exiting"); usage(options); System.exit(1); } } if (line.hasOption('r')) { String value = line.getOptionValue('r'); String[] fields = value.trim().split(" *, *"); if (fields == null || fields.length == 0) { log.error("No fields were given, exiting"); usage(options); System.exit(1); } (new FieldRemover()).removeFields(sourceIndexDirectory, destIndexDirectory, fields, version); System.exit(0); } } catch (IndexUtilityException e) { log.error("Failed to work on index:", e); System.exit(1); } catch (MissingOptionException e) { log.error("Mandatory options is missing!"); usage(options); System.exit(1); } catch (ParseException e) { log.error("Failed to parse commandline options!"); usage(options); System.exit(1); } }
From source file:lapispaste.Main.java
public static void main(String[] args) throws Exception { // create Options object Options options = new Options(); String version;//from w ww . jav a 2 s. co m version = "0.1"; // populate Options with.. well options :P options.addOption("v", false, "Display version"); options.addOption("f", true, "File to paste"); // non-critical options options.addOption("t", true, "Code language"); options.addOption("p", false, "Read from pipe"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); // assemble a map of values final Map<String, String> pastemap = new HashMap<String, String>(); if (cmd.hasOption("t")) pastemap.put("format", cmd.getOptionValue("t").toString()); else pastemap.put("format", "text"); // critical options if (cmd.hasOption("v")) System.out.println("lapispaste version " + version); else if (cmd.hasOption("f")) { File file = new File(cmd.getOptionValue("f")); StringBuffer pdata = readData(new FileReader(file)); paster(pastemap, pdata); } else if (cmd.hasOption("p")) { StringBuffer pdata = readData(new InputStreamReader(System.in)); paster(pastemap, pdata); } else { // Did not recieve what was expected HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("lapispaste [OPTIONS] [FILE]", options); } }
From source file:ezbake.thrift.VisibilityBase64Converter.java
public static void main(String[] args) { try {/*from w w w. j a v a 2s .co m*/ 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); } }
From source file:de.akquinet.dustjs.DustEngine.java
public static void main(String[] args) throws URISyntaxException { Options cmdOptions = new Options(); cmdOptions.addOption(DustOptions.CHARSET_OPTION, true, "Input file charset encoding. Defaults to UTF-8."); cmdOptions.addOption(DustOptions.DUST_OPTION, true, "Path to a custom dust.js for Rhino version."); try {/*from w w w. j a v a2s .com*/ CommandLineParser cmdParser = new GnuParser(); CommandLine cmdLine = cmdParser.parse(cmdOptions, args); DustOptions options = new DustOptions(); if (cmdLine.hasOption(DustOptions.CHARSET_OPTION)) { options.setCharset(cmdLine.getOptionValue(DustOptions.CHARSET_OPTION)); } if (cmdLine.hasOption(DustOptions.DUST_OPTION)) { options.setDust(new File(cmdLine.getOptionValue(DustOptions.DUST_OPTION)).toURI().toURL()); } DustEngine engine = new DustEngine(options); String[] files = cmdLine.getArgs(); String src = null; if (files == null || files.length == 0) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringWriter sw = new StringWriter(); char[] buffer = new char[1024]; int n = 0; while (-1 != (n = in.read(buffer))) { sw.write(buffer, 0, n); } src = sw.toString(); } if (src != null && !src.isEmpty()) { System.out.println(engine.compile(src, "test")); return; } if (files.length == 1) { System.out.println(engine.compile(new File(files[0]))); return; } if (files.length == 2) { engine.compile(new File(files[0]), new File(files[1])); return; } } catch (IOException ioe) { System.err.println("Error opening input file."); } catch (ParseException pe) { System.err.println("Error parsing arguments."); } HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar dust-engine.jar input [output] [options]", cmdOptions); System.exit(1); }
From source file:ISMAGS.CommandLineInterface.java
public static void main(String[] args) throws IOException { String folder = null, files = null, motifspec = null, output = null; Options opts = new Options(); opts.addOption("folder", true, "Folder name"); opts.addOption("linkfiles", true, "Link files seperated by spaces (format: linktype[char] directed[d/u] filename)"); opts.addOption("motif", true, "Motif description by two strings (format: linktypes)"); opts.addOption("output", true, "Output file name"); CommandLineParser parser = new PosixParser(); try {/*w w w. j a v a 2 s. co m*/ CommandLine cmd = parser.parse(opts, args); if (cmd.hasOption("folder")) { folder = cmd.getOptionValue("folder"); } if (cmd.hasOption("linkfiles")) { files = cmd.getOptionValue("linkfiles"); } if (cmd.hasOption("motif")) { motifspec = cmd.getOptionValue("motif"); } if (cmd.hasOption("output")) { output = cmd.getOptionValue("output"); } } catch (ParseException e) { Die("Error: Parsing error"); } if (print) { printBanner(folder, files, motifspec, output); } if (folder == null || files == null || motifspec == null || output == null) { Die("Error: not all options are provided"); } else { ArrayList<String> linkfiles = new ArrayList<String>(); ArrayList<String> linkTypes = new ArrayList<String>(); ArrayList<String> sourcenetworks = new ArrayList<String>(); ArrayList<String> destinationnetworks = new ArrayList<String>(); ArrayList<Boolean> directed = new ArrayList<Boolean>(); StringTokenizer st = new StringTokenizer(files, " "); while (st.hasMoreTokens()) { linkTypes.add(st.nextToken()); directed.add(st.nextToken().equals("d")); sourcenetworks.add(st.nextToken()); destinationnetworks.add(st.nextToken()); linkfiles.add(folder + st.nextToken()); } ArrayList<LinkType> allLinkTypes = new ArrayList<LinkType>(); HashMap<Character, LinkType> typeTranslation = new HashMap<Character, LinkType>(); for (int i = 0; i < linkTypes.size(); i++) { String n = linkTypes.get(i); char nn = n.charAt(0); LinkType t = typeTranslation.get(nn); if (t == null) { t = new LinkType(directed.get(i), n, i, nn, sourcenetworks.get(i), destinationnetworks.get(i)); } allLinkTypes.add(t); typeTranslation.put(nn, t); } if (print) { System.out.println("Reading network.."); } Network network = Network.readNetworkFromFiles(linkfiles, allLinkTypes); Motif motif = getMotif(motifspec, typeTranslation); if (print) { System.out.println("Starting the search.."); } MotifFinder mf = new MotifFinder(network); long tijd = System.nanoTime(); Set<MotifInstance> motifs = mf.findMotif(motif, false); tijd = System.nanoTime() - tijd; if (print) { System.out.println("Completed search in " + tijd / 1000000 + " milliseconds"); } if (print) { System.out.println("Found " + motifs.size() + " instances of " + motifspec + " motif"); } if (print) { System.out.println("Writing instances to file: " + output); } printMotifs(motifs, output); if (print) { System.out.println("Done."); } // Set<MotifInstance> motifs=null; // MotifFinder mf=null; // System.out.println("Starting the search.."); // long tstart = System.nanoTime(); // for (int i = 0; i < it; i++) { // // mf = new MotifFinder(network, allLinkTypes, true); // motifs = mf.findMotif(motif); // } // // long tend = System.nanoTime(); // double time_in_ms = (tend - tstart) / 1000000.0; // System.out.println("Found " + mf.totalFound + " motifs, " + time_in_ms + " ms"); //// System.out.println("Evaluated " + mf.totalNrMappedNodes+ " search nodes"); //// System.out.println("Found " + motifs.size() + " motifs, " + time_in_ms + " ms"); // printMotifs(motifs, output); } }