List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:com.artistech.tuio.dispatch.TuioPublish.java
public static void main(String[] args) throws InterruptedException { //read off the TUIO port from the command line int tuio_port = 3333; int zeromq_port = 5565; TuioSink.SerializeType serialize_method = TuioSink.SerializeType.PROTOBUF; Options options = new Options(); options.addOption("t", "tuio-port", true, "TUIO Port to listen on. (Default = 3333)"); options.addOption("z", "zeromq-port", true, "ZeroMQ Port to publish on. (Default = 5565)"); options.addOption("s", "serialize-method", true, "Serialization Method (JSON, OBJECT, Default = PROTOBUF)."); options.addOption("h", "help", false, "Show this message."); HelpFormatter formatter = new HelpFormatter(); try {/*from www . j a va 2s .com*/ CommandLineParser parser = new org.apache.commons.cli.BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { formatter.printHelp("tuio-zeromq-publish", options); return; } else { if (cmd.hasOption("t") || cmd.hasOption("tuio-port")) { tuio_port = Integer.parseInt(cmd.getOptionValue("t")); } if (cmd.hasOption("z") || cmd.hasOption("zeromq-port")) { zeromq_port = Integer.parseInt(cmd.getOptionValue("z")); } if (cmd.hasOption("s") || cmd.hasOption("serialize-method")) { serialize_method = (TuioSink.SerializeType) Enum.valueOf(TuioSink.SerializeType.class, cmd.getOptionValue("s")); } } } catch (ParseException | IllegalArgumentException ex) { System.err.println("Error Processing Command Options:"); formatter.printHelp("tuio-zeromq-publish", options); return; } //start up the zmq publisher ZMQ.Context context = ZMQ.context(1); // We send updates via this socket try (ZMQ.Socket publisher = context.socket(ZMQ.PUB)) { // We send updates via this socket publisher.bind("tcp://*:" + Integer.toString(zeromq_port)); //create a new TUIO sink connected at the specified port TuioSink sink = new TuioSink(); sink.setSerializationType(serialize_method); TuioClient client = new TuioClient(tuio_port); System.out.println( MessageFormat.format("Listening to TUIO message at port: {0}", Integer.toString(tuio_port))); System.out.println( MessageFormat.format("Publishing to ZeroMQ at port: {0}", Integer.toString(zeromq_port))); System.out.println(MessageFormat.format("Serializing as: {0}", serialize_method)); client.addTuioListener(sink); client.connect(); //while not halted (infinite loop...) //read any available messages and publish while (!sink.mailbox.isHalted()) { ImmutablePair<String, byte[]> msg = sink.mailbox.getMessage(); publisher.sendMore(msg.left + "." + serialize_method.toString()); publisher.send(msg.right, 0); } //cleanup } context.term(); }
From source file:com.flaptor.indextank.rpc.SearcherClient.java
public static void main(String[] args) { // create the parser CommandLineParser parser = new PosixParser(); try {/* ww w . j av a 2 s.c om*/ // parse the command line arguments CommandLine line = parser.parse(getOptions(), args); if (line.hasOption("help")) { printHelp(getOptions(), null); System.exit(1); } if (!line.hasOption("function")) { printHelp(getOptions(), null); System.exit(1); } Integer scoringFunctionIndex = Integer.valueOf(line.getOptionValue("function")); String host = line.getOptionValue("host", "localhost"); String basePort = line.getOptionValue("port", "7910"); int port = Integer.valueOf(basePort) + 2; TTransport transport; transport = new TSocket(host, port); TProtocol protocol = new TBinaryProtocol(transport); Searcher.Client client = new Searcher.Client(protocol); transport.open(); ResultSet rs = client.search(line.getArgs()[0], 0, 10, scoringFunctionIndex, Collections.<Integer, Double>emptyMap(), Lists.<CategoryFilter>newArrayList(), Lists.<RangeFilter>newArrayList(), Lists.<RangeFilter>newArrayList(), Collections.<String, String>emptyMap()); // TODO join getArgs transport.close(); System.out.println(rs); } catch (InvalidQueryException e) { e.printStackTrace(); } catch (MissingQueryVariableException e) { e.printStackTrace(); } catch (IndextankException e) { e.printStackTrace(); } catch (ParseException exp) { printHelp(getOptions(), exp.getMessage()); } catch (TTransportException e) { e.printStackTrace(); } catch (TException e) { e.printStackTrace(); } }
From source file:hisqisnoten.HisqisNoten.java
public static void main(String[] args) { options = new Options(); options.addOption("h", "help", false, "this help"); options.addOption("u", "user", true, "username for hisqis"); options.addOption("p", "pass", true, "password for hisqis"); options.addOption("c", "console", false, "console mode instead of gui mode"); CommandLineParser parser = new PosixParser(); try {/* w ww.ja v a 2 s. c o m*/ CommandLine cmdline = parser.parse(options, args); if (cmdline.hasOption("help")) { printHelp(); System.exit(0); } if (cmdline.getArgList().size() != 0) { System.err.println("Please use the new commandline options."); System.out.println(); printHelp(); System.exit(1); } HisqisSettings settings = null; HisqisSettings.genConfigPath(); for (File configpath : HisqisSettings.configpath) { if (configpath.exists() && configpath.canRead()) { settings = HisqisSettingsReader.loadDocument(configpath); if (settings != null) { break; } } } if (settings == null) { settings = new HisqisSettings(); } String user = cmdline.getOptionValue("user", null); String pass = cmdline.getOptionValue("pass", null); if (user != null) { settings.username = user; } if (pass != null) { settings.password = pass; } if (cmdline.hasOption("console")) { new HisqisConsole(settings); } else { new HisqisGUI(settings); } } catch (ParseException e) { printHelp(); } }
From source file:com.aleggeup.util.App.java
public static void main(final String[] args) { final CommandLineParser parser = new PosixParser(); final Options options = buildOptions(); File sourceFile = null;//w w w. j a va 2 s .co m File targetFile = null; try { final CommandLine commandLine = parser.parse(options, args); if (commandLine.getOptions().length == 0 || commandLine.hasOption('h')) { printHelp(options); System.exit(0); } if (commandLine.hasOption('s')) { sourceFile = new File(commandLine.getOptionValue('s')).getCanonicalFile(); } if (commandLine.hasOption('t')) { targetFile = new File(commandLine.getOptionValue('t')).getCanonicalFile(); } } catch (final ParseException e) { printHelp(options); System.exit(-1); } catch (final IOException e) { e.printStackTrace(); } }
From source file:cross.io.PropertyFileGenerator.java
/** * * @param args// w ww . j ava2 s . co m */ public static void main(String[] args) { Options options = new Options(); options.addOption("f", true, "base directory for output of files"); Option provOptions = new Option("p", true, "Comma separated list of provider classes to create Properties for"); provOptions.setRequired(true); provOptions.setValueSeparator(','); options.addOption(provOptions); CommandLineParser parser = new PosixParser(); HelpFormatter hf = new HelpFormatter(); try { File basedir = null; List<String> providers = Collections.emptyList(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { basedir = new File(cmd.getOptionValue("f")); } else { hf.printHelp("java -cp maltcms.jar " + PropertyFileGenerator.class, options); } if (cmd.hasOption("p")) { String[] str = cmd.getOptionValues("p"); providers = Arrays.asList(str); } else { hf.printHelp("java -cp maltcms.jar " + PropertyFileGenerator.class, options); } for (String provider : providers) { createProperties(provider, basedir); } } catch (ParseException ex) { Logger.getLogger(PropertyFileGenerator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:io.wcm.devops.conga.plugins.aem.tooling.crypto.cli.AemCryptoCli.java
/** * CLI entry point//from ww w .jav a 2 s. c om * @param args Command line arguments * @throws Exception Exception */ //CHECKSTYLE:OFF public static void main(String[] args) throws Exception { //CHECKSTYLE:ON CommandLine commandLine = new DefaultParser().parse(CLI_OPTIONS, args, true); boolean generateCryptoKeys = commandLine.hasOption(CRYPTO_KEYS_GENERATE); boolean ansibleVaultEncrypt = commandLine.hasOption(CRYPTO_KEYS_ANSIBLE_VAULT_ENCRYPT); File targetDir = new File(commandLine.getOptionValue(TARGET, "target")); String ansibleVaultEncryptPath = commandLine.getOptionValue(ANSIBLE_VAULT_ENCRYPT); String ansibleVaultDecryptPath = commandLine.getOptionValue(ANSIBLE_VAULT_DECRYPT); if (generateCryptoKeys) { CryptoKeys.generate(targetDir, ansibleVaultEncrypt) .forEach(file -> System.out.println("Generated: " + file.getPath())); return; } else if (StringUtils.isNotBlank(ansibleVaultEncryptPath)) { AnsibleVault.encrypt(new File(ansibleVaultEncryptPath)); return; } else if (StringUtils.isNotBlank(ansibleVaultDecryptPath)) { AnsibleVault.decrypt(new File(ansibleVaultDecryptPath)); return; } // print usage help HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(150); formatter.printHelp("java -jar conga-aem-crypto-cli-<version>.jar <arguments>", CLI_OPTIONS); }
From source file:eu.scape_project.tb.lsdr.seqfileutility.SequenceFileUtility.java
/** * Main method/* ww w .ja v a 2 s.c o m*/ * @param args Command line arguments * @throws Exception */ public static void main(String args[]) throws Exception { int res = 1; Configuration conf = new Configuration(); //conf.set("mapred.max.split.size", "16777216"); //conf.setBoolean("mapreduce.client.genericoptionsparser.used", false); GenericOptionsParser gop = new GenericOptionsParser(conf, args); ProcessParameters pc = new ProcessParameters(); CommandLineParser cmdParser = new PosixParser(); CommandLine cmd = cmdParser.parse(Options.OPTIONS, gop.getRemainingArgs()); if ((args.length == 0) || (cmd.hasOption(Options.HELP_OPT))) { Options.exit("Usage", 0); } else { Options.initOptions(cmd, pc); eu.scape_project.tb.lsdr.seqfileutility.Job j; if (!pc.isHadoopmapmode()) { j = new BatchJob(pc); j.run(); res = 0; } else { HadoopJob hj = new HadoopJob(); hj.setPc(pc); res = ToolRunner.run(conf, hj, args); if (res == 0) System.out.print(pc.getOutputDirectory()); } } System.exit(res); }
From source file:jlite.cli.ProxyDestroy.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();/* ww w. ja v a2 s. c om*/ HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(0); } if (line.hasOption("xml")) { System.out.println("<output>"); } run(line); } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if (line.hasOption("xml")) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { System.out.println("</output>"); } System.out.println(); // extra line }
From source file:msuresh.raftdistdb.AtomixDB.java
/** * Main Method which runs a Apache CLI which takes 3 different options for the 3 operations <br> * @param args <br>/*from www . jav a 2 s. co m*/ * Options : <br> * -setup numberOfReplicas numberOfPartitions -- which sets the system given thenumber of partitions number of replicas per partition<br> * -set key Value -- adds a key value pair to the DB<br> * -get key -- returns a value for the key if it exists<br> * @throws InterruptedException */ public static void main(String[] args) throws InterruptedException, ExecutionException, FileNotFoundException { Options options = new Options(); Option opt = new Option("setup", true, "Sets up the replica that run the Raft Consensus Algorithm."); opt.setArgs(3); options.addOption(opt); opt = new Option("set", true, " Add a key-value pair into the Distributed Database."); opt.setArgs(3); options.addOption(opt); opt = new Option("get", true, "Given a key gets the value from the DB"); opt.setArgs(2); options.addOption(opt); opt = new Option("clean", false, "Cleans the state information."); options.addOption(opt); opt = new Option("test", true, "Cleans the state information."); opt.setArgs(2); options.addOption(opt); try { CommandLineParser parser = new BasicParser(); CommandLine line = null; line = parser.parse(options, args); if (line.hasOption("setup")) { String[] vals = line.getOptionValues("setup"); System.out.println(vals[0]); RaftCluster.createCluster(vals[0], Integer.parseInt(vals[1]), Integer.parseInt(vals[2])); } else if (line.hasOption("set")) { String[] vals = line.getOptionValues("set"); addKey(vals[0], vals[1], vals[2]); } else if (line.hasOption("get")) { String[] vals = line.getOptionValues("get"); getKey(vals[0], vals[1]); } else if (line.hasOption("clean")) { cleanState(); } else if (line.hasOption("test")) { String[] vals = line.getOptionValues("test"); TestAtomix.createCluster(vals[0], Integer.parseInt(vals[1])); } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); } }
From source file:genql.CLIRunner.java
public static void main(String[] args) { Options options = setupOptions();//from ww w.j a v a2 s . co m CommandLineParser parser = new BasicParser(); try { // for (int i = 0; i < args.length; i++) { // System.out.println(args[i]); // } CommandLine line = parser.parse(options, args); if (line.hasOption('e')) { isEval = true; } if (line.hasOption('g')) { isGen = true; } if (line.hasOption('d')) { corpusDir = line.getOptionValue('d'); } if (line.hasOption('n')) { qcount = Integer.parseInt(line.getOptionValue('n')); } else { qcount = 10; } if (line.hasOption('o')) { outputFile = line.getOptionValue('o'); } if (line.hasOption('g')) { groundTruthQueryFile = line.getOptionValue('g'); } if (line.hasOption('q')) { generatedQueryFile = line.getOptionValue('q'); } if (line.hasOption('m')) { min_query_len = Integer.parseInt(line.getOptionValue('m')); } else { min_query_len = 2; } if (line.hasOption('x')) { max_query_len = Integer.parseInt(line.getOptionValue('x')); } else { max_query_len = 7; } if (line.hasOption('h')) { printHelpAndExit(options); } if (isGen) { MainApp.gen(corpusDir, outputFile, qcount, min_query_len, max_query_len); } else if (isEval) { final String intermediateResults = corpusDir + "/temp"; new File(intermediateResults).mkdir(); MainApp.eval(corpusDir, generatedQueryFile, groundTruthQueryFile, intermediateResults, min_query_len, max_query_len); } } catch (Exception ex) { ex.printStackTrace(); System.err.println("Unexpected exception: " + ex.getMessage()); System.exit(1); } }