List of usage examples for org.apache.commons.cli CommandLine getArgList
public List getArgList()
From source file:edu.ksu.cis.indus.staticanalyses.concurrency.independence.IndependenceDetectionCLI.java
/** * The entry point to the program via command line. * // www. j a v a 2 s .co m * @param args is the command line arguments. * @throws RuntimeException when CLI fails. */ public static void main(final String[] args) { final Options _options = new Options(); Option _option = new Option("o", "output", true, "Directory into which jimple files will be written into. [required]"); _option.setArgs(1); _option.setArgName("ouput-directory"); _option.setRequired(true); _options.addOption(_option); _option = new Option("h", "help", false, "Display message."); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path."); _option.setArgs(1); _option.setArgName("classpath"); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("useV2", false, "Use version 2 of the atomicity detection algorithm."); _options.addOption(_option); _option = new Option("scheme", false, "Scheme to indicate atomicity. Valid values are 'tag-stmt' and 'tag-region'. By default, 'tag-stmt' " + "scheme is used. "); _option.setArgs(1); _option.setArgName("scheme-name"); _options.addOption(_option); _option = new Option("S", "scope", true, "The scope that should be analyzed."); _option.setArgs(1); _option.setArgName("scope"); _option.setRequired(false); _options.addOption(_option); final CommandLineParser _parser = new GnuParser(); try { final CommandLine _cl = _parser.parse(_options, args); if (_cl.hasOption("h")) { final String _cmdLineSyn = "java " + IndependenceDetectionCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, _options); System.exit(1); } if (_cl.getArgList().isEmpty()) { throw new MissingArgumentException("Please specify atleast one class."); } final IndependenceDetectionCLI _cli; if (_cl.hasOption("useV2")) { _cli = new IndependenceDetectionCLI(new IndependentStmtDetectorv2()); } else { _cli = new IndependenceDetectionCLI(new IndependentStmtDetector()); } if (_cl.hasOption('p')) { _cli.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('S')) { _cli.setScopeSpecFile(_cl.getOptionValue('S')); } _cli.setClassNames(_cl.getArgList()); _cli.setOutputDir(_cl.getOptionValue('o')); _cli.<ITokens>execute(_cl); } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); System.out.println("Error while parsing command line." + _e); final String _cmdLineSyn = "java " + IndependenceDetectionCLI.class.getName() + " <options> <classnames>"; (new HelpFormatter()).printHelp(_cmdLineSyn, "Options are:", _options, ""); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:com.linkedin.python.importer.ImporterCLI.java
public static void main(String[] args) throws Exception { Options options = createOptions();/*from ww w . j a va2 s . c o m*/ CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, args); if (line.hasOption("quite")) { Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); root.setLevel(Level.WARN); } final File repoPath = new File(line.getOptionValue("repo")); final DependencySubstitution replacements = new DependencySubstitution(buildSubstitutionMap(line)); repoPath.mkdirs(); if (!repoPath.exists() || !repoPath.isDirectory()) { throw new RuntimeException( "Unable to continue, " + repoPath.getAbsolutePath() + " does not exist, or is not a directory"); } for (String dependency : line.getArgList()) { new DependencyDownloader(dependency, repoPath, replacements).download(); } logger.info("Execution Finished!"); }
From source file:com.act.lcms.MassCalculator2.java
public static void main(String[] args) throws Exception { CommandLine cl = CLI_UTIL.parseCommandLine(args); if (cl.hasOption(OPTION_LICENSE_FILE)) { LOGGER.info("Using license file at %s", cl.getOptionValue(OPTION_LICENSE_FILE)); LicenseManager.setLicenseFile(cl.getOptionValue(OPTION_LICENSE_FILE)); }//from www . j a v a 2 s . com List<String> inchis = new ArrayList<>(); if (cl.hasOption(OPTION_INPUT_FILE)) { try (BufferedReader reader = new BufferedReader(new FileReader(cl.getOptionValue(OPTION_INPUT_FILE)))) { String line; while ((line = reader.readLine()) != null) { inchis.add(line); } } } if (cl.getArgList().size() > 0) { LOGGER.info("Reading %d InChIs from the command line", cl.getArgList().size()); inchis.addAll(cl.getArgList()); } try (PrintWriter writer = new PrintWriter( cl.hasOption(OPTION_OUTPUT_FILE) ? new FileWriter(cl.getOptionValue(OPTION_OUTPUT_FILE)) : new OutputStreamWriter(System.out))) { writer.format("InChI\tMass\tCharge\n"); for (String inchi : inchis) { try { Pair<Double, Integer> massAndCharge = calculateMassAndCharge(inchi); writer.format("%s\t%.6f\t%3d\n", inchi, massAndCharge.getLeft(), massAndCharge.getRight()); } catch (MolFormatException e) { LOGGER.error("Unable to compute mass for %s: %s", inchi, e.getMessage()); } } } }
From source file:com.aerospike.examples.travel.FlighAggregation.java
public static void main(String[] args) throws AerospikeException { try {/*from w ww . jav 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."); 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; } FlighAggregation as = new FlighAggregation(host, port, namespace, set); as.init(); as.work(); } catch (Exception e) { log.error("Critical error", e); } }
From source file:com.aerospike.examples.ldt.ttl.LdtExpire.java
public static void main(String[] args) throws AerospikeException { try {/* ww w . ja v a 2s . 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.msd.gin.halyard.tools.HalyardUpdate.java
/** * Main of the HalyardUpdate//from ww w .jav a2 s .c o m * @param args String command line arguments * @throws Exception throws Exception in case of any problem */ public static void main(final String args[]) throws Exception { if (conf == null) conf = new Configuration(); Options options = new Options(); options.addOption(newOption("h", null, "Prints this help")); options.addOption(newOption("v", null, "Prints version")); options.addOption(newOption("s", "source_htable", "Source HBase table with Halyard RDF store")); options.addOption( newOption("q", "sparql_query", "SPARQL tuple or graph query executed to export the data")); try { CommandLine cmd = new PosixParser().parse(options, args); if (args.length == 0 || cmd.hasOption('h')) { printHelp(options); return; } if (cmd.hasOption('v')) { Properties p = new Properties(); try (InputStream in = HalyardUpdate.class .getResourceAsStream("/META-INF/maven/com.msd.gin.halyard/hbasesail/pom.properties")) { if (in != null) p.load(in); } System.out.println("Halyard Update version " + p.getProperty("version", "unknown")); return; } if (!cmd.getArgList().isEmpty()) throw new ParseException("Unknown arguments: " + cmd.getArgList().toString()); for (char c : "sq".toCharArray()) { if (!cmd.hasOption(c)) throw new ParseException("Missing mandatory option: " + c); } for (char c : "sq".toCharArray()) { String s[] = cmd.getOptionValues(c); if (s != null && s.length > 1) throw new ParseException("Multiple values for option: " + c); } SailRepository rep = new SailRepository( new HBaseSail(conf, cmd.getOptionValue('s'), false, 0, true, 0, null)); rep.initialize(); try { Update u = rep.getConnection().prepareUpdate(QueryLanguage.SPARQL, cmd.getOptionValue('q')); LOG.info("Update execution started"); u.execute(); LOG.info("Update finished"); } finally { rep.shutDown(); } } catch (Exception exp) { System.out.println(exp.getMessage()); printHelp(options); throw exp; } }
From source file:bs.java
public static void main(String[] args) throws FileNotFoundException { Options options = new Options(); options.addOption(help);/*from w ww .j ava 2 s .c om*/ options.addOption(version); options.addOption(loadPath); options.addOption(loadable); options.addOption(eval); // args = new String[] { "Reflection.bs" }; try { Bs.init(); CommandLineParser argParser = new PosixParser(); CommandLine line = argParser.parse(options, args); if (line.hasOption(HELP)) { help(options); } if (line.hasOption(VERSION)) { version(); } if (line.hasOption(LOAD_PATH)) { loadPath(line.getOptionValue(LOAD_PATH)); } if (line.hasOption(EVAL)) { eval(line.getOptionValue(EVAL)); } if (line.hasOption(LOADABLE)) { loadable(line.getOptionValue(LOADABLE)); } List<?> rest = line.getArgList(); if (rest.size() > 0) { eval(rest); } else { repl(); } } catch (ParseException e) { help(options); } }
From source file:edu.ksu.cis.indus.staticanalyses.flow.instances.ofa.OFAXMLizerCLI.java
/** * The entry point to the program via command line. * //w w w . j a v a2 s . com * @param args is the command line arguments. * @throws RuntimeException when object flow analysis fails. */ public static void main(final String[] args) { final Options _options = new Options(); Option _option = new Option("c", "cumulative", false, "Consider all root methods in the same execution."); _options.addOption(_option); _option = new Option("o", "output", true, "Directory into which xml files will be written into."); _option.setArgs(1); _options.addOption(_option); _option = new Option("j", "jimple", false, "Dump xmlized jimple."); _options.addOption(_option); _option = new Option("h", "help", false, "Display message."); _options.addOption(_option); _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path."); _option.setArgs(1); _option.setArgName("classpath"); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("t", "ofa-type", false, "Type of analysis : fioi, fsoi, fios, fsos, fioirt, fsoirt."); _option.setArgs(1); _option.setArgName("type"); _option.setOptionalArg(false); _option.setRequired(true); _options.addOption(_option); _option = new Option("S", "scope", true, "The scope that should be analyzed."); _option.setArgs(1); _option.setArgName("scope"); _option.setRequired(false); _options.addOption(_option); final PosixParser _parser = new PosixParser(); try { final CommandLine _cl = _parser.parse(_options, args); if (_cl.hasOption("h")) { printUsage(_options); System.exit(1); } String _outputDir = _cl.getOptionValue('o'); if (_outputDir == null) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Defaulting to current directory for output."); } _outputDir = "."; } if (_cl.getArgList().isEmpty()) { throw new MissingArgumentException("Please specify atleast one class."); } final OFAXMLizerCLI _cli = new OFAXMLizerCLI(); _cli.xmlizer.setXmlOutputDir(_outputDir); _cli.xmlizer.setGenerator(new UniqueJimpleIDGenerator()); _cli.setCumulative(_cl.hasOption('c')); _cli.setClassNames(_cl.getArgList()); _cli.type = _cl.getOptionValue('t'); if (_cl.hasOption('p')) { _cli.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('S')) { _cli.setScopeSpecFile(_cl.getOptionValue('S')); } _cli.initialize(); _cli.<ITokens>execute(_cl.hasOption('j')); } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); System.out.println("Error while parsing command line. \n" + _e); printUsage(_options); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:DcmRcv.java
@SuppressWarnings("unchecked") public static void main(String[] args) { CommandLine cl = parse(args); DcmRcv dcmrcv = new DcmRcv(); final List argList = cl.getArgList(); String port = (String) argList.get(0); String[] aetPort = split(port, ':', 1); dcmrcv.setPort(parseInt(aetPort[1], "illegal port number", 1, 0xffff)); if (aetPort[0] != null) { String[] aetHost = split(aetPort[0], '@', 0); dcmrcv.setAEtitle(aetHost[0]);// ww w. j av a 2 s . co m if (aetHost[1] != null) { dcmrcv.setHostname(aetHost[1]); } } if (cl.hasOption("dest")) dcmrcv.setDestination(cl.getOptionValue("dest")); if (cl.hasOption("defts")) dcmrcv.setTransferSyntax(ONLY_DEF_TS); else if (cl.hasOption("native")) dcmrcv.setTransferSyntax(cl.hasOption("bigendian") ? NATIVE_TS : NATIVE_LE_TS); else if (cl.hasOption("bigendian")) dcmrcv.setTransferSyntax(NON_RETIRED_TS); if (cl.hasOption("reaper")) dcmrcv.setAssociationReaperPeriod(parseInt(cl.getOptionValue("reaper"), "illegal argument of option -reaper", 1, Integer.MAX_VALUE)); if (cl.hasOption("idleTO")) dcmrcv.setIdleTimeout(parseInt(cl.getOptionValue("idleTO"), "illegal argument of option -idleTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("requestTO")) dcmrcv.setRequestTimeout(parseInt(cl.getOptionValue("requestTO"), "illegal argument of option -requestTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("releaseTO")) dcmrcv.setReleaseTimeout(parseInt(cl.getOptionValue("releaseTO"), "illegal argument of option -releaseTO", 1, Integer.MAX_VALUE)); if (cl.hasOption("soclosedelay")) dcmrcv.setSocketCloseDelay(parseInt(cl.getOptionValue("soclosedelay"), "illegal argument of option -soclosedelay", 1, 10000)); if (cl.hasOption("rspdelay")) dcmrcv.setDimseRspDelay( parseInt(cl.getOptionValue("rspdelay"), "illegal argument of option -rspdelay", 0, 10000)); if (cl.hasOption("rcvpdulen")) dcmrcv.setMaxPDULengthReceive( parseInt(cl.getOptionValue("rcvpdulen"), "illegal argument of option -rcvpdulen", 1, 10000) * KB); if (cl.hasOption("sndpdulen")) dcmrcv.setMaxPDULengthSend( parseInt(cl.getOptionValue("sndpdulen"), "illegal argument of option -sndpdulen", 1, 10000) * KB); if (cl.hasOption("sosndbuf")) dcmrcv.setSendBufferSize( parseInt(cl.getOptionValue("sosndbuf"), "illegal argument of option -sosndbuf", 1, 10000) * KB); if (cl.hasOption("sorcvbuf")) dcmrcv.setReceiveBufferSize( parseInt(cl.getOptionValue("sorcvbuf"), "illegal argument of option -sorcvbuf", 1, 10000) * KB); if (cl.hasOption("bufsize")) dcmrcv.setFileBufferSize( parseInt(cl.getOptionValue("bufsize"), "illegal argument of option -bufsize", 1, 10000) * KB); dcmrcv.setPackPDV(!cl.hasOption("pdv1")); dcmrcv.setTcpNoDelay(!cl.hasOption("tcpdelay")); if (cl.hasOption("async")) dcmrcv.setMaxOpsPerformed( parseInt(cl.getOptionValue("async"), "illegal argument of option -async", 0, 0xffff)); dcmrcv.initTransferCapability(); if (cl.hasOption("tls")) { String cipher = cl.getOptionValue("tls"); if ("NULL".equalsIgnoreCase(cipher)) { dcmrcv.setTlsWithoutEncyrption(); } else if ("3DES".equalsIgnoreCase(cipher)) { dcmrcv.setTls3DES_EDE_CBC(); } else if ("AES".equalsIgnoreCase(cipher)) { dcmrcv.setTlsAES_128_CBC(); } else { exit("Invalid parameter for option -tls: " + cipher); } if (cl.hasOption("nossl2")) { dcmrcv.disableSSLv2Hello(); } dcmrcv.setTlsNeedClientAuth(!cl.hasOption("noclientauth")); if (cl.hasOption("keystore")) { dcmrcv.setKeyStoreURL(cl.getOptionValue("keystore")); } if (cl.hasOption("keystorepw")) { dcmrcv.setKeyStorePassword(cl.getOptionValue("keystorepw")); } if (cl.hasOption("keypw")) { dcmrcv.setKeyPassword(cl.getOptionValue("keypw")); } if (cl.hasOption("truststore")) { dcmrcv.setTrustStoreURL(cl.getOptionValue("truststore")); } if (cl.hasOption("truststorepw")) { dcmrcv.setTrustStorePassword(cl.getOptionValue("truststorepw")); } try { dcmrcv.initTLS(); } catch (Exception e) { System.err.println("ERROR: Failed to initialize TLS context:" + e.getMessage()); System.exit(2); } } try { dcmrcv.start(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.aerospike.examples.frequencycap.FrequencyCap.java
public static void main(String[] args) throws AerospikeException { try {// w ww . j a va2s . co m Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: 172.28.128.6)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("u", "usage", false, "Print usage."); options.addOption("l", "load", false, "Load data."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); String host = cl.getOptionValue("h", "172.28.128.6"); 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; } FrequencyCap as = new FrequencyCap(host, port, namespace, set); if (cl.hasOption("l")) { as.generateDataDateInKey(); as.generateDataDateInBin(); } else { as.simulateWorkDateInKey(); as.simulateWorkDateInBin(); } } catch (Exception e) { log.error("Critical error", e); } }