List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:eu.interedition.collatex.http.Server.java
public static void main(String... args) { try {//ww w . ja v a 2s. 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:HBBRequestor.java
public static void main(String[] args) throws Exception { String hostId = ""; String partnerId = ""; String userId = ""; CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "host", true, "EBICS Host ID"); options.addOption("p", "partner", true, "Registred Partner ID for you user"); options.addOption("u", "user", true, "User ID to initiate"); // Parse the program arguments CommandLine commandLine = parser.parse(options, args); if (!commandLine.hasOption('h')) { System.out.println("Host-ID is mandatory"); System.exit(0);/*from www . ja v a 2 s .com*/ } else { hostId = commandLine.getOptionValue('h'); System.out.println("host: " + hostId); } if (!commandLine.hasOption('p')) { System.out.println("Partner-ID is mandatory"); System.exit(0); } else { partnerId = commandLine.getOptionValue('p'); System.out.println("partnerId: " + partnerId); } if (!commandLine.hasOption('u')) { System.out.println("User-ID is mandatory"); System.exit(0); } else { userId = commandLine.getOptionValue('u'); System.out.println("userId: " + userId); } HBBRequestor hbbRequestor; PasswordCallback pwdHandler; Product product; hbbRequestor = new HBBRequestor(); product = new Product("kopiLeft Dev 1.0", Locale.FRANCE, null); pwdHandler = new UserPasswordHandler(userId, "2012"); // Load alredy created user hbbRequestor.loadUser(hostId, partnerId, userId, pwdHandler); // Send hbb Requets hbbRequestor.sendHPBRequest(userId, product); // Perform save for the changed data hbbRequestor.quit(); }
From source file:FDLRequestor.java
public static void main(String[] args) throws Exception { String hostId = ""; String partnerId = ""; String userId = ""; CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "host", true, "EBICS Host ID"); options.addOption("p", "partner", true, "Registred Partner ID for you user"); options.addOption("u", "user", true, "User ID to initiate"); // Parse the program arguments CommandLine commandLine = parser.parse(options, args); if (!commandLine.hasOption('h')) { System.out.println("Host-ID is mandatory"); System.exit(0);/*from w ww .ja v a 2 s . com*/ } else { hostId = commandLine.getOptionValue('h'); System.out.println("host: " + hostId); } if (!commandLine.hasOption('p')) { System.out.println("Partner-ID is mandatory"); System.exit(0); } else { partnerId = commandLine.getOptionValue('p'); System.out.println("partnerId: " + partnerId); } if (!commandLine.hasOption('u')) { System.out.println("User-ID is mandatory"); System.exit(0); } else { userId = commandLine.getOptionValue('u'); System.out.println("userId: " + userId); } FDLRequestor fdlRequestor; PasswordCallback pwdHandler; Product product; String filePath; fdlRequestor = new FDLRequestor(); product = new Product("kopiLeft Dev 1.0", Locale.FRANCE, null); pwdHandler = new UserPasswordHandler(userId, "2012"); // Load alredy created user fdlRequestor.loadUser(hostId, partnerId, userId, pwdHandler); filePath = System.getProperty("user.home") + File.separator + "download.txt"; // Send FDL Requets fdlRequestor.fetchFile(filePath, userId, product, OrderType.FDL, true, null, null); }
From source file:com.discursive.jccook.cmdline.CliComplexExample.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "help", false, "Print this usage information"); options.addOption("v", "verbose", false, "Print out VERBOSE debugging information"); OptionGroup optionGroup = new OptionGroup(); optionGroup.addOption(OptionBuilder.hasArg(true).create('f')); optionGroup.addOption(OptionBuilder.hasArg(true).create('m')); options.addOptionGroup(optionGroup); CommandLine commandLine = parser.parse(options, args); boolean verbose = false; String file = ""; String mail = ""; if (commandLine.hasOption('h')) { System.out.println("Help Message"); System.exit(0);/*from w ww . ja v a 2s . c om*/ } if (commandLine.hasOption('v')) { verbose = true; } if (commandLine.hasOption('f')) { file = commandLine.getOptionValue('f'); } else if (commandLine.hasOption('m')) { mail = commandLine.getOptionValue('m'); } System.exit(0); }
From source file:de.fhg.iais.asc.ASC.java
/** * main method//from w ww .ja v a 2s.co m * * @param arga * @throws ParseException */ public static void main(final String[] arga) throws ParseException { Options options = createASCOptions(); CommandLineParser parser = new BasicParser(); CommandLine cl = parser.parse(options, arga); if (cl.hasOption("help")) { new HelpFormatter().printHelp("java -jar asc.jar [OPTIONS]*", options); return; } List<AscConfiguration> configs = readCommandLine(cl); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(lc); lc.reset(); configurator.doConfigure(HOMEDIR.getFile("conf/asc/logback.xml")); } catch (JoranException je) { je.printStackTrace(); // NOSONAR } StatusPrinter.printInCaseOfErrorsOrWarnings(lc); setGlobalProxy(configs); initXSLUtilityClasses(configs); ASCWorkflow asc = new ASCWorkflow(TRANSFORMATIONSDIR, HOMEDIR); asc.run(configs); RestIngestMiniFactory.shutdown(); }
From source file:edu.cmu.lti.oaqa.annographix.apps.SolrIndexApp.java
public static void main(String[] args) { Options options = new Options(); options.addOption("t", null, true, "Text File"); options.addOption("a", null, true, "Annotation File"); options.addOption("u", null, true, "Solr URI"); options.addOption("n", null, true, "Batch size"); options.addOption(/* w ww.j a v a 2 s . com*/ OptionBuilder.withLongOpt(TEXT_FIELD_ARG).withDescription("Text field name").hasArg().create()); options.addOption(OptionBuilder.withLongOpt(ANNOT_FIELD_ARG).withDescription("Annotation field name") .hasArg().create()); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("t")) { docTextFile = cmd.getOptionValue("t"); } else { Usage("Specify Text File"); } if (cmd.hasOption("a")) { docAnnotFile = cmd.getOptionValue("a"); } else { Usage("Specify Annotation File"); } if (cmd.hasOption("u")) { solrURI = cmd.getOptionValue("u"); } else { Usage("Specify Solr URI"); } if (cmd.hasOption("n")) { batchQty = Integer.parseInt(cmd.getOptionValue("n")); } String textFieldName = UtilConst.DEFAULT_TEXT4ANNOT_FIELD; String annotFieldName = UtilConst.DEFAULT_ANNOT_FIELD; if (cmd.hasOption(TEXT_FIELD_ARG)) { textFieldName = cmd.getOptionValue(TEXT_FIELD_ARG); } if (cmd.hasOption(ANNOT_FIELD_ARG)) { annotFieldName = cmd.getOptionValue(ANNOT_FIELD_ARG); } System.out.println(String.format("Annotated text field: '%s', annotation field: '%s'", textFieldName, annotFieldName)); // Ignoring return value here SolrUtils.parseAndCheckConfig(solrURI, textFieldName, annotFieldName); System.out.println("Config is fine!"); DocumentReader.readDoc(docTextFile, textFieldName, docAnnotFile, batchQty, new SolrDocumentIndexer(solrURI, textFieldName, annotFieldName)); } catch (ParseException e) { Usage("Cannot parse arguments"); } catch (Exception e) { System.err.println("Terminating due to an exception: " + e); System.exit(1); } }
From source file:FULRequestor.java
public static void main(String[] args) throws Exception { String hostId = ""; String partnerId = ""; String userId = ""; CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "host", true, "EBICS Host ID"); options.addOption("p", "partner", true, "Registred Partner ID for you user"); options.addOption("u", "user", true, "User ID to initiate"); // Parse the program arguments CommandLine commandLine = parser.parse(options, args); if (!commandLine.hasOption('h')) { System.out.println("Host-ID is mandatory"); System.exit(0);/*from w w w. j av a 2 s.co m*/ } else { hostId = commandLine.getOptionValue('h'); System.out.println("host: " + hostId); } if (!commandLine.hasOption('p')) { System.out.println("Partner-ID is mandatory"); System.exit(0); } else { partnerId = commandLine.getOptionValue('p'); System.out.println("partnerId: " + partnerId); } if (!commandLine.hasOption('u')) { System.out.println("User-ID is mandatory"); System.exit(0); } else { userId = commandLine.getOptionValue('u'); System.out.println("userId: " + userId); } FULRequestor hbbRequestor; PasswordCallback pwdHandler; Product product; String filePath; hbbRequestor = new FULRequestor(); product = new Product("kopiLeft Dev 1.0", Locale.FRANCE, null); pwdHandler = new UserPasswordHandler(userId, "2012"); // Load alredy created user hbbRequestor.loadUser(hostId, partnerId, userId, pwdHandler); filePath = System.getProperty("user.home") + File.separator + "test.txt"; // Send FUL Requets hbbRequestor.sendFile(filePath, userId, product); }
From source file:com.msbmsb.genealogeo.ui.cli.GenealoGeoCLI.java
/** * Command-line interface/* ww w . j av a2 s .c o m*/ */ public static void main(String[] args) throws Exception { GenealoGeoCLI cli = new GenealoGeoCLI(); // parse command line String inputFileName = ""; try { CommandLineParser parser = new GnuParser(); CommandLine cl = parser.parse(cli.opts, args); inputFileName = cl.getOptionValue("file"); if (cl.hasOption("help")) throw new ParseException(null); } catch (ParseException e) { cli.usage(e.getMessage()); } // require an input file if (inputFileName == null) { cli.usage("Error: No input file given."); } // verify and load the input file File inputFile = new File(inputFileName); if (!inputFile.exists()) { cli.usage("Error: Could not open input file: " + inputFileName); } cli.load(inputFile); // testing functions cli.genealoGeo.printFamilies(); cli.genealoGeo.printLocations(); }
From source file:mx.unam.fesa.mss.MSSMain.java
/** * @param args/*from ww w . j av a 2 s .c om*/ */ @SuppressWarnings("static-access") public static void main(String[] args) { // // managing command line options using commons-cli // Options options = new Options(); // help option // options.addOption( OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP)); // port option // options.addOption(OptionBuilder.withDescription("The port in which the MineSweeperServer will listen to.") .hasArg().withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT)); // parsing options // int port = DEFAULT_PORT; try { // using GNU standard // CommandLine line = new GnuParser().parse(options, args); if (line.hasOption(OPT_HELP)) { new HelpFormatter().printHelp("mss [options]", options); return; } if (line.hasOption(OPT_PORT)) { try { port = (Integer) line.getOptionObject(OPT_PORT); } catch (Exception e) { } } } catch (ParseException e) { System.err.println("Could not parse command line options correctly: " + e.getMessage()); return; } // // configuring logging services // try { LogManager.getLogManager() .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE)); } catch (Exception e) { throw new Error("Could not load logging properties file", e); } // // setting up UDP server // try { new MSServer(port); } catch (Exception e) { LoggerFactory.getLogger(MSSMain.class).error("Could not execute MineSweeper server: ", e); } }
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 *//*w w w.j a v a 2 s . c o 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); } }