List of usage examples for org.apache.commons.cli OptionBuilder isRequired
public static OptionBuilder isRequired()
From source file:edu.harvard.med.iccbl.screensaver.io.cells.CellImporter.java
public static void main(String[] args) { try {//from ww w . j a va 2 s . c om final CellImporter app = new CellImporter(args); app.addCommandLineOption( OptionBuilder.isRequired().hasArg(true).withArgName("file").withLongOpt("input-file") .withDescription("The path of a CSV file containing the Cell Information").create("f")); app.processOptions(true, false); File file = app.getCommandLineOptionValue("f", File.class); final CellParser importer = (CellParser) app.getSpringBean("cellParser"); importer.load(file); } catch (Exception e) { log.error("application exception", e); System.exit(1); } }
From source file:com.temenos.interaction.rimdsl.generator.launcher.Main.java
public static void main(String[] args) { // handle command line options final Options options = new Options(); OptionBuilder.withArgName("src"); OptionBuilder.withDescription("Model source"); OptionBuilder.hasArg();/*from w ww .j a va2 s .c om*/ OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optSrc = OptionBuilder.create("src"); OptionBuilder.withArgName("targetdir"); OptionBuilder.withDescription("Generator target directory"); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optTargetDir = OptionBuilder.create("targetdir"); options.addOption(optSrc); options.addOption(optTargetDir); // create the command line parser final CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (final ParseException exp) { System.err.println("Parsing arguments failed. Reason: " + exp); wrongCall(options); return; } // execute the generator Injector injector = new RIMDslStandaloneSetup().createInjectorAndDoEMFRegistration(); Generator generator = injector.getInstance(Generator.class); File srcFile = new File(line.getOptionValue(optSrc.getArgName())); if (srcFile.exists()) { boolean result = false; if (srcFile.isDirectory()) { result = generator.runGeneratorDir(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } else { result = generator.runGenerator(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } System.out.println("Code generation finished [" + result + "]"); } else { System.out.println("Src dir not found."); } }
From source file:com.temenos.interaction.rimdsl.generator.launcher.MainSpringPRD.java
public static void main(String[] args) { // handle command line options final Options options = new Options(); OptionBuilder.withArgName("src"); OptionBuilder.withDescription("Model source"); OptionBuilder.hasArg();//from w w w. j av a2s .com OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optSrc = OptionBuilder.create("src"); OptionBuilder.withArgName("targetdir"); OptionBuilder.withDescription("Generator target directory"); OptionBuilder.hasArg(); OptionBuilder.isRequired(); OptionBuilder.withValueSeparator(' '); Option optTargetDir = OptionBuilder.create("targetdir"); options.addOption(optSrc); options.addOption(optTargetDir); // create the command line parser final CommandLineParser parser = new GnuParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (final ParseException exp) { System.err.println("Parsing arguments failed. Reason: " + exp); wrongCall(options); return; } // execute the generator Injector injector = new RIMDslStandaloneSetupSpringPRD().createInjectorAndDoEMFRegistration(); Generator generator = injector.getInstance(Generator.class); File srcFile = new File(line.getOptionValue(optSrc.getArgName())); if (srcFile.exists()) { boolean result = false; if (srcFile.isDirectory()) { result = generator.runGeneratorDir(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } else { result = generator.runGenerator(srcFile.getPath(), line.getOptionValue(optTargetDir.getArgName())); } System.out.println("Code generation finished [" + result + "]"); } else { System.out.println("Src dir not found."); } }
From source file:com.hurence.logisland.runner.SparkJobLauncher.java
/** * main entry point//ww w. j av a 2s.c o m * * @param args */ public static void main(String[] args) { logger.info("starting StreamProcessingRunner"); ////////////////////////////////////////// // Commande lien management Parser parser = new GnuParser(); Options options = new Options(); String helpMsg = "Print this message."; Option help = new Option("help", helpMsg); options.addOption(help); OptionBuilder.withArgName(AGENT); OptionBuilder.withLongOpt("agent-quorum"); OptionBuilder.isRequired(); OptionBuilder.hasArg(); OptionBuilder.withDescription("logisland agent quorum like host1:8081,host2:8081"); Option agent = OptionBuilder.create(AGENT); options.addOption(agent); OptionBuilder.withArgName(JOB); OptionBuilder.withLongOpt("job-name"); OptionBuilder.isRequired(); OptionBuilder.hasArg(); OptionBuilder.withDescription("logisland agent quorum like host1:8081,host2:8081"); Option job = OptionBuilder.create(JOB); options.addOption(job); String logisland = " \n" + " ???????? ????? ?? ??\n" + " \n" + " ???? ?? \n" + "?? ?\n" + "??????? ?????? ?????? ?????????????????? ???? ?????????? v0.10.0-SNAPSHOT\n\n\n"; System.out.println(logisland); Optional<EngineContext> engineInstance = Optional.empty(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); String agentQuorum = line.getOptionValue(AGENT); String jobName = line.getOptionValue(JOB); // instanciate engine and all the processor from the config engineInstance = new RestComponentFactory(agentQuorum).getEngineContext(jobName); assert engineInstance.isPresent(); assert engineInstance.get().isValid(); logger.info("starting Logisland session version {}", engineInstance.get()); } catch (Exception e) { logger.error("unable to launch runner : {}", e.toString()); } try { // start the engine EngineContext engineContext = engineInstance.get(); engineInstance.get().getEngine().start(engineContext); } catch (Exception e) { logger.error("something went bad while running the job : {}", e); System.exit(-1); } }
From source file:com.hurence.logisland.runner.StreamProcessingRunner.java
/** * main entry point/*from www. ja v a 2 s .com*/ * * @param args */ public static void main(String[] args) { logger.info("starting StreamProcessingRunner"); ////////////////////////////////////////// // Commande lien management Parser parser = new GnuParser(); Options options = new Options(); String helpMsg = "Print this message."; Option help = new Option("help", helpMsg); options.addOption(help); OptionBuilder.withArgName("conf"); OptionBuilder.withLongOpt("config-file"); OptionBuilder.isRequired(); OptionBuilder.hasArg(); OptionBuilder.withDescription("config file path"); Option conf = OptionBuilder.create("conf"); options.addOption(conf); Optional<EngineContext> engineInstance = Optional.empty(); try { System.out.println(BannerLoader.loadBanner()); // parse the command line arguments CommandLine line = parser.parse(options, args); String configFile = line.getOptionValue("conf"); // load the YAML config LogislandConfiguration sessionConf = ConfigReader.loadConfig(configFile); // instantiate engine and all the processor from the config engineInstance = ComponentFactory.getEngineContext(sessionConf.getEngine()); if (!engineInstance.isPresent()) { throw new IllegalArgumentException("engineInstance could not be instantiated"); } if (!engineInstance.get().isValid()) { throw new IllegalArgumentException("engineInstance is not valid with input configuration !"); } logger.info("starting Logisland session version {}", sessionConf.getVersion()); logger.info(sessionConf.getDocumentation()); } catch (Exception e) { logger.error("unable to launch runner", e); System.exit(-1); } String engineName = engineInstance.get().getEngine().getIdentifier(); try { // start the engine EngineContext engineContext = engineInstance.get(); logger.info("start engine {}", engineName); engineInstance.get().getEngine().start(engineContext); logger.info("awaitTermination for engine {}", engineName); engineContext.getEngine().awaitTermination(engineContext); System.exit(0); } catch (Exception e) { logger.error("something went bad while running the job {} : {}", engineName, e); System.exit(-1); } }
From source file:com.svds.tailer2kafka.main.Main.java
/** * Given command-line arguments, create GenericConsumerGroup * //from ww w .j av a2s . c o m * @param args command-line arguments to parse * @throws IOException */ public static void main(String[] args) throws IOException, InterruptedException { Options options = new Options(); options.addOption(OptionBuilder.isRequired().withLongOpt(TOPICNAME).withDescription("Kafka topic name") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(METADATABROKERLIST) .withDescription("Kafka metadata.broker.list").hasArg().create()); options.addOption( OptionBuilder.isRequired().withLongOpt(FILENAME).withDescription("Log filename").hasArg().create()); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { LOG.error(e.getMessage(), e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("com.svds.tailer2kafka.main.Main", options); throw new IOException("Missing Args"); } Main main = new Main(); main.doWork(cmd); }
From source file:edu.harvard.med.iccbl.screensaver.io.libraries.MasterStockPlateMappingLoader.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException { final MasterStockPlateMappingLoader app = new MasterStockPlateMappingLoader(args); app.addCommandLineOption(OptionBuilder.isRequired().hasArg(true).withArgName("file") .withLongOpt("input-file") .withDescription(/*from w w w.j av a 2s .co m*/ "The path of a CSV file containing the stock plate mapping data (master stock plate number, stock plate number, quadrant") .create("f")); app.processOptions(true, false); GenericEntityDAO dao = (GenericEntityDAO) app.getSpringBean("genericEntityDao"); dao.doInTransaction(new DAOTransaction() { @Override public void runTransaction() { try { app.load(); } catch (Exception e) { throw new DAOTransactionRollbackException(e); } } }); }
From source file:eu.fbk.utils.twm.FormPageSearcher.java
public static void main(final String args[]) throws Exception { String logConfig = System.getProperty("log-config"); if (logConfig == null) { logConfig = "configuration/log-config.txt"; }/*from ww w.j a v a 2s.c om*/ PropertyConfigurator.configure(logConfig); final Options options = new Options(); try { OptionBuilder.withArgName("index"); OptionBuilder.hasArg(); OptionBuilder.withDescription("open an index with the specified name"); OptionBuilder.isRequired(); OptionBuilder.withLongOpt("index"); final Option indexNameOpt = OptionBuilder.create("i"); OptionBuilder.withArgName("interactive-mode"); OptionBuilder.withDescription("enter in the interactive mode"); OptionBuilder.withLongOpt("interactive-mode"); final Option interactiveModeOpt = OptionBuilder.create("t"); OptionBuilder.withArgName("search"); OptionBuilder.hasArg(); OptionBuilder.withDescription("search for the specified key"); OptionBuilder.withLongOpt("search"); final Option searchOpt = OptionBuilder.create("s"); OptionBuilder.withArgName("key-freq"); OptionBuilder.hasArg(); OptionBuilder.withDescription("read the keys' frequencies from the specified file"); OptionBuilder.withLongOpt("key-freq"); final Option freqFileOpt = OptionBuilder.create("f"); OptionBuilder.withArgName("minimum-freq"); // Option keyFieldNameOpt = // OptionBuilder.withArgName("key-field-name").hasArg().withDescription("use the specified name for the field key").withLongOpt("key-field-name").create("k"); // Option valueFieldNameOpt = // OptionBuilder.withArgName("value-field-name").hasArg().withDescription("use the specified name for the field value").withLongOpt("value-field-name").create("v"); final Option minimumKeyFreqOpt = OptionBuilder.hasArg() .withDescription("minimum key frequency of cached values (default is " + DEFAULT_MIN_FREQ + ")") .withLongOpt("minimum-freq").create("m"); OptionBuilder.withArgName("int"); final Option notificationPointOpt = OptionBuilder.hasArg() .withDescription( "receive notification every n pages (default is " + DEFAULT_NOTIFICATION_POINT + ")") .withLongOpt("notification-point").create("b"); options.addOption("h", "help", false, "print this message"); options.addOption("v", "version", false, "output version information and exit"); options.addOption(indexNameOpt); options.addOption(interactiveModeOpt); options.addOption(searchOpt); options.addOption(freqFileOpt); // options.addOption(keyFieldNameOpt); // options.addOption(valueFieldNameOpt); options.addOption(minimumKeyFreqOpt); options.addOption(notificationPointOpt); final CommandLineParser parser = new PosixParser(); final CommandLine line = parser.parse(options, args); if (line.hasOption("help") || line.hasOption("version")) { throw new ParseException(""); } int minFreq = DEFAULT_MIN_FREQ; if (line.hasOption("minimum-freq")) { minFreq = Integer.parseInt(line.getOptionValue("minimum-freq")); } int notificationPoint = DEFAULT_NOTIFICATION_POINT; if (line.hasOption("notification-point")) { notificationPoint = Integer.parseInt(line.getOptionValue("notification-point")); } final FormPageSearcher pageFormSearcher = new FormPageSearcher(line.getOptionValue("index")); pageFormSearcher.setNotificationPoint(notificationPoint); /* * logger.debug(line.getOptionValue("key-field-name") + "\t" + * line.getOptionValue("value-field-name")); if (line.hasOption("key-field-name")) { * pageFormSearcher.setKeyFieldName(line.getOptionValue("key-field-name")); } if * (line.hasOption("value-field-name")) { * pageFormSearcher.setValueFieldName(line.getOptionValue("value-field-name")); } */ if (line.hasOption("key-freq")) { pageFormSearcher.loadCache(line.getOptionValue("key-freq"), minFreq); } if (line.hasOption("search")) { logger.debug("searching " + line.getOptionValue("search") + "..."); final FreqSetSearcher.Entry[] result = pageFormSearcher.search(line.getOptionValue("search")); logger.info(Arrays.toString(result)); } if (line.hasOption("interactive-mode")) { pageFormSearcher.interactive(); } } catch (final ParseException e) { // oops, something went wrong if (e.getMessage().length() > 0) { System.out.println("Parsing failed: " + e.getMessage() + "\n"); } final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(400, "java -cp dist/thewikimachine.jar org.fbk.cit.hlt.thewikimachine.index.FormPageSearcher", "\n", options, "\n", true); } }
From source file:edu.harvard.med.iccbl.screensaver.io.cells.ExperimentalCellInformationImporter.java
public static void main(String[] args) { try {/*from w ww . jav a 2s . c o m*/ final ExperimentalCellInformationImporter app = new ExperimentalCellInformationImporter(args); app.addCommandLineOption( OptionBuilder.isRequired().hasArg(true).withArgName("file").withLongOpt("input-file") .withDescription("The path of a CSV file containing the Cell Information").create("f")); // app.addCommandLineOption(OptionBuilder.hasArg(false).withLongOpt("delete-existing") // .withDescription("Delete existing ExperimentalCellInformation").create("de")); app.processOptions(true, false); File file = app.getCommandLineOptionValue("f", File.class); final ExperimentalCellInformationParser parser = (ExperimentalCellInformationParser) app .getSpringBean("experimentalCellInformationParser"); parser.load(file); } catch (Exception e) { log.error("application exception", e); System.exit(1); } }
From source file:com.svds.genericconsumer.main.GenericConsumerGroup.java
/** * Given command-line arguments, create GenericConsumerGroup * // ww w .j av a 2 s. com * @param args command-line arguments to parse * @throws IOException */ public static void main(String[] args) throws IOException { LOG.info("HELLO from main"); Options options = new Options(); options.addOption(OptionBuilder.isRequired().withLongOpt(ZOOKEEPER).withDescription("Zookeeper servers") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(GROUPID).withDescription("Kafka group id").hasArg() .create()); options.addOption(OptionBuilder.isRequired().withLongOpt(TOPICNAME).withDescription("Kafka topic name") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(THREADS).withType(Number.class) .withDescription("Number of threads").hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(CONSUMERCLASS) .withDescription("Consumer Class from processing topic name").hasArg().create()); options.addOption(OptionBuilder.withLongOpt(PARAMETERS) .withDescription("Parameters needed for the consumer Class if needed").hasArgs() .withValueSeparator(',').create()); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { LOG.error(e.getMessage(), e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("GenericConsumerGroup.main", options); throw new IOException(e); } try { GenericConsumerGroup consumerGroupExample = new GenericConsumerGroup(); consumerGroupExample.doWork(cmd); } catch (ParseException ex) { LOG.error("Error parsing command-line args"); throw new IOException(ex); } }