List of usage examples for org.apache.commons.cli CommandLineParser parse
CommandLine parse(Options options, String[] arguments) throws ParseException;
From source file:com.matthatem.ai.search.applications.MSASolver.java
public static void main(String[] args) { Options options = createOptions();/*from w ww . j a v a 2 s . c om*/ CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { e.printStackTrace(); System.exit(1); } MSA msa = createMSAInstance(cmd); SearchAlgorithm algo = createSearchAlgorithm(cmd, msa); System.gc(); long t = System.currentTimeMillis(); SearchResult<MSAState> result = algo.search(); long td = System.currentTimeMillis(); result.setAlgorithm(algoString); result.setInitialH((int) msa.getHeuristic().getInitH()); result.setStartTime(t); result.setEndTime(td); System.out.println(result); //System.out.println(msa.alignmentToString()); System.out.println(msa.alignmentToMSFString()); }
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 ww w.j a v a 2 s . c o m 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 a v a 2s. 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 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:ie.peternagy.jcrypto.cli.JCryptoCli.java
public static void main(String[] args) { long startTime = System.currentTimeMillis(); try {// w ww .ja v a 2s .c o m CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(OPTIONS, args); isVerbose = line.hasOption('v'); routeParams(line); if (isVerbose) { System.out.printf("\n Process finished in %dms\n\n", System.currentTimeMillis() - startTime); } } catch (org.apache.commons.cli.ParseException ex) { printCliHelp(); //@todo: override the logger if not in debug mode Logger.getLogger(JCryptoCli.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.bachelor.boulmier.workmaster.WorkMaster.java
public static void main(String[] args) throws IOException, InterruptedException { defineOptions();/*www. j a va 2 s. c om*/ CommandLineParser parser = new BasicParser(); CommandLine cmd; try { cmd = parser.parse(options, args); if (cmd.hasOption(MasterConfig.CMD.CLILONGOPT)) { cliEnabled = true; } if (cmd.hasOption(MasterConfig.CMD.DEBUGLONGOPT)) { debug = true; } if (cmd.hasOption(MasterConfig.CMD.MAXVMLONGOPT)) { maxVM = Integer.valueOf(cmd.getOptionValue(MasterConfig.CMD.MAXVMLONGOPT)); } if (cmd.hasOption(MasterConfig.CMD.VERBOSELONGOPT)) { verbose = true; } if (cmd.hasOption(MasterConfig.CMD.REMOTEWSLONGOPT)) { webServer = cmd.getOptionValue(MasterConfig.CMD.REMOTEWSLONGOPT); if (!MasterConfig.DEFAULT.IP_PORT_PATTERN.matcher(webServer).matches()) { throw new ParseException("Given IP:PORT does not match pattern"); } } if (cmd.hasOption(MasterConfig.CMD.HELPLONGOPT)) { printHelp(); } logger = LoggerFactory.getLogger(); QueuingService.get() .send(RequestBuilder.builder().withExecutableName(ExecutableName.CAT) .with(RequestProperty.CLIENT_EMAIL, "anthony.boulmier.cfpt@gmail.com") .with(RequestProperty.JOB_IDENTIFIER, UUID.randomUUID().toString()) .with(RequestProperty.ARGS, "JobExecutor.log").create()); Thread.sleep(3000); } catch (ParseException pe) { logger.error(pe.getMessage()); printHelp(); } }
From source file:com.haulmont.mp2xls.MessagePropertiesProcessor.java
public static void main(String[] args) { Options options = new Options(); options.addOption(READ_OPT, "read", false, "read messages from project and save to XLS"); options.addOption(WRITE_OPT, "write", false, "load messages from XLS and write to project"); options.addOption(OVERWRITE_OPT, "overwrite", false, "overwrite existing messages by changed messages from XLS file"); options.addOption(PROJECT_DIR_OPT, "projectDir", true, "project root directory"); options.addOption(XLS_FILE_OPT, "xlsFile", true, "XLS file with translations"); options.addOption(LOG_FILE_OPT, "logFile", true, "log file"); options.addOption(LANGUAGES_OPT, "languages", true, "list of locales separated by comma, for example: 'de,fr'"); CommandLineParser parser = new DefaultParser(); CommandLine cmd;/*from w w w .ja v a2s.c o m*/ try { cmd = parser.parse(options, args); if ((!cmd.hasOption(READ_OPT) && !cmd.hasOption(WRITE_OPT)) || !cmd.hasOption(PROJECT_DIR_OPT) || !cmd.hasOption(XLS_FILE_OPT) || !cmd.hasOption(LANGUAGES_OPT)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Messages To/From XLS Convertor", options); System.exit(-1); } if (cmd.hasOption(READ_OPT) && cmd.hasOption(WRITE_OPT)) { System.out.println("Please provide either 'read' or 'write' option"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Messages To/From XLS Convertor", options); System.exit(-1); } Set<String> languages = getLanguages(cmd.getOptionValue(LANGUAGES_OPT)); if (cmd.hasOption(READ_OPT)) { LocalizationsBatch localizationsBatch = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT)); localizationsBatch.setScanLocalizationIds(languages); LocalizationBatchExcelWriter.exportToXls(localizationsBatch, cmd.getOptionValue(XLS_FILE_OPT)); } else if (cmd.hasOption(WRITE_OPT)) { LocalizationsBatch sourceLocalization = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT)); sourceLocalization.setScanLocalizationIds(languages); LocalizationsBatch fileLocalization = new LocalizationsBatch(cmd.getOptionValue(XLS_FILE_OPT), cmd.getOptionValue(PROJECT_DIR_OPT)); fileLocalization.setScanLocalizationIds(languages); LocalizationBatchFileWriter fileWriter = new LocalizationBatchFileWriter(sourceLocalization, fileLocalization); String logFile = StringUtils.isNotEmpty(cmd.getOptionValue(LOG_FILE_OPT)) ? cmd.getOptionValue(LOG_FILE_OPT) : "log.xls"; fileWriter.process(logFile, cmd.hasOption(OVERWRITE_OPT)); } } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } }
From source file:de.fhg.iais.asc.ASC.java
/** * main method/* w w w . j a v a 2 s . c om*/ * * @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:havocx42.Program.java
public static void main(String[] args) throws ParseException { try {//from www. j a v a 2s . c om initRootLogger(); } catch (SecurityException | IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); return; } try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e1) { LOGGER.log(Level.WARNING, "Unable to set Look and Feel", e1); } Options options = new Options(); options.addOption("nogui", false, "run as a command line tool, must also supply -target and -source arguments"); options.addOption("source", true, "source directory where the PR weapons folder has been extracted"); options.addOption("target", true, "target file to write to"); options.addOption("version", false, "print the version information and exit"); options.addOption("help", false, "print this message"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("version")) { System.out.println("PRStats " + VERSION); System.out.println("Written by havocx42"); return; } if ((cmd.hasOption("nogui") && (!cmd.hasOption("source") || !cmd.hasOption("target"))) || cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("PRStats", options); return; } final String target; final String source; source = cmd.getOptionValue("source"); target = cmd.getOptionValue("target"); LOGGER.info("Source Argument: " + source); LOGGER.info("Target Argument: " + target); if (!cmd.hasOption("nogui")) { EventQueue.invokeLater(new Runnable() { @SuppressWarnings("unused") public void run() { try { Gui window = new Gui(source, target); } catch (Exception e) { e.printStackTrace(); } } }); return; } File targetFile = new File(target); File sourceFile = new File(source); Controller controller = new Controller(); controller.run(sourceFile, targetFile); }
From source file:com.github.xwgou.namesurfer.fxui.JFXNameSurfer.java
public static void main(String[] args) { JSurferOptions options = new JSurferOptions(); HelpFormatter formatter = new HelpFormatter(); String cmd_line_syntax = "namesurfer [options]"; String help_header = "NameSurfer renders beautiful algebraic surfaces derived from your name."; String help_footer = ""; try {//from w ww . j a va 2s . c o m CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption(JSurferOptions.HELP)) { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); return; } if (cmd.hasOption(JSurferOptions.VERSION)) { System.out.println(JFXNameSurfer.class.getPackage().getImplementationVersion()); return; } fullscreen = cmd.hasOption(JSurferOptions.FULLSCREEN); disable_buttons = cmd.hasOption(JSurferOptions.DISABLE_BUTTONS); InputStream rules = PinyinTranslator.RULES_PATH.openStream(); if (cmd.hasOption(JSurferOptions.RULES)) { rules = new FileInputStream(cmd.getOptionValue(JSurferOptions.RULES)); } InputStream keywords = PinyinTranslator.KEYWORDS_PATH.openStream(); if (cmd.hasOption(JSurferOptions.KEYWORDS)) { keywords = new FileInputStream(cmd.getOptionValue(JSurferOptions.KEYWORDS)); } translator = new PinyinTranslator(rules, keywords); launch(args); } catch (Throwable t) { logger.error("Exception during application startup", t); formatter.printHelp("help", options); System.exit(-1); } }
From source file:com.ottogroup.bi.spqr.websocket.server.SPQRWebSocketServer.java
/** * Checks the command-line settings and ramps up the server * @param args arguments passed from command-line * @throws ParseException indicates that parsing the command-line failed for any reason * @throws InterruptedException //from w ww .j a v a 2s . co m * @throws IOException */ public static void main(String[] args) throws ParseException, IOException, InterruptedException { //////////////////////////////////////////////////////////////////////// // evaluate command-line and ensure that it provides valid input CommandLineParser parser = new PosixParser(); CommandLine commandLine = parser.parse(getOptions(), args); if (commandLine.hasOption(CFG_HELP)) { new HelpFormatter().printHelp("spqr-websocket-server", getOptions()); return; } if (!commandLine.hasOption(CFG_CONFIGURATION_FILE)) { new HelpFormatter().printHelp("spqr-websocket-server", "", getOptions(), "Missing required configuration file"); return; } // //////////////////////////////////////////////////////////////////////// new SPQRWebSocketServer().run(commandLine.getOptionValue(CFG_CONFIGURATION_FILE)); }