List of usage examples for org.apache.commons.cli HelpFormatter printHelp
public void printHelp(String cmdLineSyntax, Options options, boolean autoUsage)
options
with the specified command line syntax. From source file:eu.itesla_project.online.mpi.Master.java
public static void main(String[] args) throws Exception { try {//from w w w. j a v a2 s . c o m CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(OPTIONS, args); String mode = line.getOptionValue("m"); Path tmpDir = Paths.get(line.getOptionValue("t")); Class<?> statisticsFactoryClass = Class.forName(line.getOptionValue("f")); Path statisticsDbDir = Paths.get(line.getOptionValue("s")); String statisticsDbName = line.getOptionValue("d"); int coresPerRank = Integer.parseInt(line.getOptionValue("n")); Path stdOutArchive = line.hasOption("o") ? Paths.get(line.getOptionValue("o")) : null; MpiExecutorContext mpiExecutorContext = new MultiStateNetworkAwareMpiExecutorContext(); ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1); ExecutorService executorService = MultiStateNetworkAwareExecutors.newCachedThreadPool(); try { MpiStatisticsFactory statisticsFactory = statisticsFactoryClass .asSubclass(MpiStatisticsFactory.class).newInstance(); MpiStatistics statistics = statisticsFactory.create(statisticsDbDir, statisticsDbName); try (ComputationManager computationManager = new MpiComputationManager(tmpDir, statistics, mpiExecutorContext, coresPerRank, false, stdOutArchive)) { OnlineConfig config = OnlineConfig.load(); try (LocalOnlineApplication application = new LocalOnlineApplication(config, computationManager, scheduledExecutorService, executorService, true)) { switch (mode) { case "ui": System.out.println("LocalOnlineApplication created"); System.out.println("Waiting till shutdown"); // indefinitely wait for JMX commands //TimeUnit.DAYS.sleep(Integer.MAX_VALUE); synchronized (application) { try { application.wait(); } catch (InterruptedException ex) { } } break; default: throw new IllegalArgumentException("Invalid mode " + mode); } } } } finally { mpiExecutorContext.shutdown(); executorService.shutdown(); scheduledExecutorService.shutdown(); executorService.awaitTermination(15, TimeUnit.MINUTES); scheduledExecutorService.awaitTermination(15, TimeUnit.MINUTES); } } catch (ParseException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("master", OPTIONS, true); System.exit(-1); } catch (Throwable t) { LOGGER.error(t.toString(), t); System.exit(-1); } }
From source file:com.cws.esolutions.core.main.SQLUtility.java
public static final void main(final String[] args) { final String methodName = SQLUtility.CNAME + "#main(final String[] args)"; if (DEBUG) {//from w w w. j a va 2 s . c o m DEBUGGER.debug(methodName); DEBUGGER.debug("Value: {}", (Object) args); } if (args.length == 0) { HelpFormatter usage = new HelpFormatter(); usage.printHelp(SQLUtility.CNAME, options, true); return; } final String coreConfiguration = (StringUtils.isBlank(System.getProperty("coreConfigFile"))) ? SQLUtility.CORE_SVC_CONFIG : System.getProperty("coreConfigFile"); final String securityConfiguration = (StringUtils.isBlank(System.getProperty("secConfigFile"))) ? SQLUtility.CORE_LOG_CONFIG : System.getProperty("secConfigFile"); final String coreLogging = (StringUtils.isBlank(System.getProperty("coreLogConfig"))) ? SQLUtility.SEC_SVC_CONFIG : System.getProperty("coreLogConfig"); final String securityLogging = (StringUtils.isBlank(System.getProperty("secLogConfig"))) ? SQLUtility.SEC_LOG_CONFIG : System.getProperty("secLogConfig"); if (DEBUG) { DEBUGGER.debug("String coreConfiguration: {}", coreConfiguration); DEBUGGER.debug("String securityConfiguration: {}", securityConfiguration); DEBUGGER.debug("String coreLogging: {}", coreLogging); DEBUGGER.debug("String securityLogging: {}", securityLogging); } try { SecurityServiceInitializer.initializeService(securityConfiguration, securityLogging, false); CoreServiceInitializer.initializeService(coreConfiguration, coreLogging, false, true); } catch (CoreServiceException csx) { System.err .println("An error occurred while loading configuration data: " + csx.getCause().getMessage()); System.exit(1); } catch (SecurityServiceException sx) { System.err.println("An error occurred while loading configuration data: " + sx.getCause().getMessage()); System.exit(1); } Options options = new Options(); try { throw new ParseException("nothing to see here"); } catch (ParseException px) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(SQLUtility.CNAME, options, true); } }
From source file:de.mpi_bremen.mgg.FastaValidatorUi.java
/** * @param args the command line arguments *//*from w ww . j a v a 2 s . com*/ public static void main(String[] args) { // create Options object Options options = new Options(); // add verbose option options.addOption("v", "verbose", false, "verbose mode"); // add inputfile option options.addOption("f", "file", true, "FASTA-formatted input file"); // add help option options.addOption("h", "help", false, "print this help message"); // add sequencetype option options.addOption("t", "seqtype", true, "sequence type (allowed values: all|dna|rna|protein)"); // add gui-mode option options.addOption("nogui", false, "start in non-interactive mode"); //create the cmdline-parser GnuParser parser = new GnuParser(); // parse the command line arguments try { //get cmdline arguments cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println(exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("FastaValidatorUi", options, true); System.exit(1); //indicate error to external environment } if (cmdline.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("FastaValidatorUi", options, true); System.exit(0); //indicate no errors to external environment } //which mode? (gui or cmdline) if (cmdline.hasOption("nogui")) { //cmdline-mode //create new cmdline-gui FvCmdline cmdlinegui = new FvCmdline(); //set verbosity cmdlinegui.setVerbose(cmdline.hasOption("v")); //handle input file if (cmdline.hasOption("f")) { cmdlinegui.setInput(cmdline.getOptionValue("f")); } //set sequencetype if (cmdline.hasOption("t")) { cmdlinegui.setSequencetype(getSeqtype(cmdline.getOptionValue("t"))); } else { cmdlinegui.setSequencetype(FastaValidator.Sequencetype.ALL); } //trigger validation and exit with exitcode int exitcode = cmdlinegui.validate().getValue(); System.exit(exitcode); } else { //gui-mode //start gui in its own thread SwingUtilities.invokeLater(new Runnable() { public void run() { FvGui w = new FvGui(); } }); } }
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 va2s . c om*/ 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); } }
From source file:eu.scape_project.pc.droid.cli.DroidCli.java
public static void main(String[] args) { // Static for command line option parsing DroidCli tc = new DroidCli(); CommandLineParser cmdParser = new PosixParser(); try {/*from w w w .j av a 2 s . c om*/ CommandLine cmd = cmdParser.parse(OPTIONS, args); if ((args.length == 0) || (cmd.hasOption(HELP_OPT))) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(Constants.USAGE, OPTIONS, true); System.exit(0); } else { if (cmd.hasOption(DIR_OPT) && cmd.getOptionValue(DIR_OPT) != null) { String dirStr = cmd.getOptionValue(DIR_OPT); logger.info("Directory: " + dirStr); // *** start timer long startClock = System.currentTimeMillis(); try { tc.processFiles(new File(dirStr)); } catch (FileNotFoundException ex) { logger.error("File not found", ex); } catch (IOException ex) { logger.error("I/O Exception", ex); } // *** stop timer long elapsedTimeMillis = System.currentTimeMillis() - startClock; logger.info("Identification finished after " + elapsedTimeMillis + " milliseconds"); } else { logger.error("No directory given."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(Constants.USAGE, OPTIONS, true); System.exit(1); } } } catch (ParseException ex) { logger.error("Problem parsing command line arguments.", ex); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(Constants.USAGE, OPTIONS, true); System.exit(1); } }
From source file:net.sf.mpaxs.spi.computeHost.StartUp.java
/** * * @param args/*www . j a v a2 s. co m*/ */ public static void main(String args[]) { FileHandler handler; try { handler = new FileHandler("computeHost.log"); Logger logger = Logger.getLogger(StartUp.class.getName()); logger.addHandler(handler); } catch (IOException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } Options options = new Options(); Option[] optionArray = new Option[] { OptionBuilder.withArgName("configuration").hasArg().isRequired() .withDescription("URL to configuration file for compute host").create("c") }; for (Option opt : optionArray) { options.addOption(opt); } if (args.length == 0) { HelpFormatter hf = new HelpFormatter(); hf.printHelp(StartUp.class.getCanonicalName(), options, true); System.exit(1); } GnuParser gp = new GnuParser(); try { CommandLine cl = gp.parse(options, args); try { URL configURL = new URL(cl.getOptionValue("c")); PropertiesConfiguration cfg = new PropertiesConfiguration(configURL); StartUp su = new StartUp(cfg); } catch (ConfigurationException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } catch (MalformedURLException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } } catch (ParseException ex) { Logger.getLogger(StartUp.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.ase2015.CdoQueryThrownExceptions.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);/*w w w. j a va2s. com*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryThrownExceptions.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before query: {0}", MessageUtil.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<TypeAccess> list = ASE2015JavaQueries.getThrownExceptions(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after query: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); } transaction.close(); session.close(); } finally { server.stop(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.ase2015.CdoQueryInvisibleMethodDeclarations.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);/*from ww w . j a v a 2 s . c o m*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryInvisibleMethodDeclarations.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before query: {0}", MessageUtil.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = ASE2015JavaQueries.getInvisibleMethodDeclarations(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after query: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); } transaction.close(); session.close(); } finally { server.stop(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.ase2015.CdoQueryGetBranchStatements.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);/*from w w w . j a v a2s.c o m*/ inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryGetBranchStatements.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before query: {0}", MessageUtil.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); Set<TextElement> list = ASE2015JavaQueries.getCommentsTagContent(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after query: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); } transaction.close(); session.close(); } finally { server.stop(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.ase2015.CdoQuerySpecificInvisibleMethodDeclarations.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);//from ww w . j ava 2s. co m inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQuerySpecificInvisibleMethodDeclarations.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before query: {0}", MessageUtil.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = ASE2015JavaQueries .getSpecificInvisibleMethodDeclarations(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after query: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); } transaction.close(); session.close(); } finally { server.stop(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }