List of usage examples for org.apache.commons.cli CommandLine hasOption
public boolean hasOption(char opt)
From source file:com.vaadin.buildhelpers.CompileTheme.java
/** * @param args//from ww w . j a v a2 s . com * @throws IOException * @throws ParseException */ public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); options.addOption("t", "theme", true, "the theme to compile"); options.addOption("v", "theme-version", true, "the version to add to the compiled theme"); options.addOption("f", "theme-folder", true, "the folder containing the theme"); CommandLineParser parser = new PosixParser(); CommandLine params = parser.parse(options, args); if (!params.hasOption("theme") || !params.hasOption("theme-folder")) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CompileTheme.class.getName(), options); return; } String themeName = params.getOptionValue("theme"); String themeFolder = params.getOptionValue("theme-folder"); String themeVersion = params.getOptionValue("theme-version"); // Regular theme try { processSassTheme(themeFolder, themeName, "styles", themeVersion); System.out.println("Compiling theme " + themeName + " styles successful"); } catch (Exception e) { System.err.println("Compiling theme " + themeName + " styles failed"); e.printStackTrace(); } // Legacy theme w/o .themename{} wrapping try { processSassTheme(themeFolder, themeName, "legacy-styles", themeVersion); System.out.println("Compiling theme " + themeName + " legacy-styles successful"); } catch (Exception e) { System.err.println("Compiling theme " + themeName + " legacy-styles failed"); e.printStackTrace(); } }
From source file:Compiler.java
/** A command line entry point to the mini Java compiler. *///from w w w.j ava 2 s .c o m public static void main(String[] args) { CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("L", "LLVM", true, "LLVM Bitcode Output Location."); options.addOption("x", "x86", true, "x86 Output File Location"); options.addOption("l", "llvm", false, "Dump Human Readable LLVM Code."); options.addOption("i", "input", true, "Compile to x86 Assembly."); options.addOption("I", "interp", false, "Run the interpreter."); options.addOption("h", "help", false, "Print this help message."); options.addOption("V", "version", false, "Version information."); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("v")) { System.out.println("MiniJava Compiler"); System.out.println("Written By Mark Jones http://web.cecs.pdx.edu/~mpj/"); System.out.println("Extended for LLVM by Mitch Souders and Mark Smith"); } if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar mjc.jar -i <INPUT> (--x86 <OUT>|--LLVM <OUT>|--llvm)", options); System.exit(0); } int errors = 0; if (!cmd.hasOption("i")) { System.out.println("-i|--input requires a MiniJava input file"); System.out.println("--help for more info."); errors++; } if (!cmd.hasOption("x") && !cmd.hasOption("l") && !cmd.hasOption("L") && !cmd.hasOption("I")) { System.out.println("--x86|--llvm|--LLVM|--interp required for some sort of output."); System.out.println("--help for more info."); errors++; } if (errors > 0) { System.exit(1); } String inputFile = cmd.getOptionValue("i"); compile(inputFile, cmd); } catch (ParseException exp) { System.out.println("Argument Error: " + exp.getMessage()); } }
From source file:com.github.zk1931.zabkv.Main.java
public static void main(String[] args) throws Exception { // Options for command arguments. Options options = new Options(); Option port = OptionBuilder.withArgName("port").hasArg(true).isRequired(true).withDescription("port number") .create("port"); Option ip = OptionBuilder.withArgName("ip").hasArg(true).isRequired(true) .withDescription("current ip address").create("ip"); Option join = OptionBuilder.withArgName("join").hasArg(true).withDescription("the addr of server to join.") .create("join"); Option help = OptionBuilder.withArgName("h").hasArg(false).withLongOpt("help") .withDescription("print out usages.").create("h"); options.addOption(port).addOption(ip).addOption(join).addOption(help); CommandLineParser parser = new BasicParser(); CommandLine cmd; try {/*from ww w . jav a 2 s. c o m*/ cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("zabkv", options); return; } } catch (ParseException exp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("zabkv", options); return; } int zabPort = Integer.parseInt(cmd.getOptionValue("port")); String myIp = cmd.getOptionValue("ip"); if (zabPort < 5000 && zabPort >= 5010) { System.err.println("port parameter can have value only between 5000 & 5010"); System.exit(1); } int serverPort = zabPort % 5000 + 8000; Database db = new Database(myIp, zabPort, cmd.getOptionValue("join")); Server server = new Server(serverPort); ServletHandler handler = new ServletHandler(); server.setHandler(handler); ServletHolder holder = new ServletHolder(new RequestHandler(db)); handler.addServletWithMapping(holder, "/*"); server.start(); server.join(); System.out.println("hi"); }
From source file:di.uniba.it.tee2.wiki.Wikidump2Index.java
/** * language xml_dump output_dir encoding * * @param args the command line arguments */// ww w .j a v a2 s . c o m public static void main(String[] args) { try { CommandLine cmd = cmdParser.parse(options, args); if (cmd.hasOption("l") && cmd.hasOption("d") && cmd.hasOption("o")) { encoding = cmd.getOptionValue("e", "UTF-8"); minTextLegth = Integer.parseInt(cmd.getOptionValue("m", "4000")); if (cmd.hasOption("p")) { pageLimit = Integer.parseInt(cmd.getOptionValue("p")); } Wikidump2Index builder = new Wikidump2Index(); builder.init(cmd.getOptionValue("l"), cmd.getOptionValue("o")); builder.build(cmd.getOptionValue("d"), cmd.getOptionValue("l")); } else { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Index Wikipedia dump (single thread)", options, true); } } catch (Exception ex) { Logger.getLogger(Wikidump2Index.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.omade.monitor.ClientApplication.java
public static void main(String[] args) throws Exception { logger.info("program start ..."); @SuppressWarnings("deprecation") CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "help", false, "Print this usage information"); options.addOption("c", "config", true, "configure the properties"); options.addOption("v", "version", false, "Print out Version information"); CommandLine commandLine = parser.parse(options, args); String configPath = "application.properties"; if (commandLine.hasOption('h')) { logger.info("Help Message"); System.exit(0);/*from w w w . jav a 2s. c om*/ } if (commandLine.hasOption('v')) { logger.info("Version Message"); } if (commandLine.hasOption('c')) { logger.info("Configuration Message"); configPath = commandLine.getOptionValue('c'); logger.info("configPath" + configPath); try { config = PropertiesUtil.getProperties(configPath); } catch (IllegalStateException e) { logger.error(e.getMessage()); System.exit(-1); } } executeFixedRate(); }
From source file:com.adobe.aem.demomachine.RegExp.java
public static void main(String[] args) throws IOException { String fileName = null;// w w w . j a v a 2s . c om String regExp = null; String position = null; String value = "n/a"; List<String> allMatches = new ArrayList<String>(); // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Filename"); options.addOption("r", true, "RegExp"); options.addOption("p", true, "Position"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { fileName = cmd.getOptionValue("f"); } if (cmd.hasOption("f")) { regExp = cmd.getOptionValue("r"); } if (cmd.hasOption("p")) { position = cmd.getOptionValue("p"); } if (fileName == null || regExp == null || position == null) { System.out.println("Command line parameters: -f fileName -r regExp -p position"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } String content = readFile(fileName, Charset.defaultCharset()); if (content != null) { Matcher m = Pattern.compile(regExp).matcher(content); while (m.find()) { String group = m.group(); int pos = group.indexOf(".zip"); if (pos > 0) { group = group.substring(0, pos); } logger.debug("RegExp: " + m.group() + " found returning " + group); allMatches.add(group); } if (allMatches.size() > 0) { if (position.equals("first")) { value = allMatches.get(0); } if (position.equals("last")) { value = allMatches.get(allMatches.size() - 1); } } } System.out.println(value); }
From source file:com.adobe.aem.demomachine.Updates.java
public static void main(String[] args) { String rootFolder = null;//from w w w .ja v a2s. c o m // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { rootFolder = cmd.getOptionValue("f"); } } catch (Exception e) { System.exit(-1); } Properties md5properties = new Properties(); try { URL url = new URL( "https://raw.githubusercontent.com/Adobe-Marketing-Cloud/aem-demo-machine/master/conf/checksums.properties"); InputStream in = url.openStream(); Reader reader = new InputStreamReader(in, "UTF-8"); md5properties.load(reader); reader.close(); } catch (Exception e) { System.out.println("Error: Cannot connect to GitHub.com to check for updates"); System.exit(-1); } System.out.println(AemDemoConstants.HR); int nbUpdateAvailable = 0; List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths); for (String[] path : listPaths) { if (path.length == 5) { logger.debug(path[1]); File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : "")); if (pathFolder.exists()) { String newMd5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false); logger.debug("MD5 is: " + newMd5); String oldMd5 = md5properties.getProperty("demo.md5." + path[0]); if (oldMd5 == null || oldMd5.length() == 0) { logger.error("Cannot find MD5 for " + path[0]); System.out.println(path[2] + " : Cannot find M5 checksum"); continue; } if (newMd5.equals(oldMd5)) { continue; } else { System.out.println(path[2] + " : New update available" + (path[0].equals("0") ? " (use 'git pull' to get the latest changes)" : "")); nbUpdateAvailable++; } } else { System.out.println(path[2] + " : Not installed"); } } } if (nbUpdateAvailable == 0) { System.out.println("Your AEM Demo Machine is up to date!"); } System.out.println(AemDemoConstants.HR); }
From source file:net.extemporal.test.Main.java
public static void main(String[] args) throws IOException { Options opts = new Options(); opts.addOption(OptionBuilder.withDescription("email id for 1st account").hasArg(true).create("e1")); opts.addOption(/*from w w w. jav a2 s. c o m*/ OptionBuilder.withDescription("either gmail password or full URNs for Store and Transport servers") .hasOptionalArgs(3).create("c1")); opts.addOption(OptionBuilder.withDescription("email id for 2nd account").hasArg(true).create("e2")); opts.addOption( OptionBuilder.withDescription("either gmail password or full URNs for Store and Transport servers") .hasOptionalArgs(3).create("c2")); // this parses the command line but doesn't throw an exception on unknown options try { CommandLine cmd = new GnuParser().parse(opts, args, true); if (cmd.hasOption("e1") && cmd.hasOption("c1")) { String e = cmd.getOptionValue("e1"); String[] accounts = cmd.getOptionValues("c1"); if (accounts.length == 1) email1 = EmailTestPlatform.getGMailCredentials(e, accounts[0]); else if (email1.length == 2) { email1 = new String[] { e, accounts[0], accounts[1] }; } } if (cmd.hasOption("e2") && cmd.hasOption("c2")) { String e = cmd.getOptionValue("e2"); String[] accounts = cmd.getOptionValues("c2"); if (accounts.length == 1) email2 = EmailTestPlatform.getGMailCredentials(e, accounts[0]); else if (email2.length == 2) { email2 = new String[] { e, accounts[0], accounts[1] }; } } } catch (ParseException pex) { System.err.println("error parsing commandline: " + pex); } ShellFactory.createConsoleShell("test-harness", "Type '?list' to see valid commands", new Main()) .commandLoop(); }
From source file:com.ibm.crail.namenode.NameNode.java
public static void main(String args[]) throws Exception { LOG.info("initalizing namenode "); CrailConfiguration conf = new CrailConfiguration(); CrailConstants.updateConstants(conf); URI uri = CrailUtils.getPrimaryNameNode(); String address = uri.getHost(); int port = uri.getPort(); if (args != null) { Option addressOption = Option.builder("a").desc("ip address namenode is started on").hasArg().build(); Option portOption = Option.builder("p").desc("port namenode is started on").hasArg().build(); Options options = new Options(); options.addOption(portOption);//from w w w.j a v a2 s . co m options.addOption(addressOption); CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 0, args.length)); if (line.hasOption(addressOption.getOpt())) { address = line.getOptionValue(addressOption.getOpt()); } if (line.hasOption(portOption.getOpt())) { port = Integer.parseInt(line.getOptionValue(portOption.getOpt())); } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Namenode", options); System.exit(-1); } } String namenode = "crail://" + address + ":" + port; long serviceId = CrailUtils.getServiceId(namenode); long serviceSize = CrailUtils.getServiceSize(); if (!CrailUtils.verifyNamenode(namenode)) { throw new Exception("Namenode address/port [" + namenode + "] has to be listed in crail.namenode.address " + CrailConstants.NAMENODE_ADDRESS); } CrailConstants.NAMENODE_ADDRESS = namenode + "?id=" + serviceId + "&size=" + serviceSize; CrailConstants.printConf(); CrailConstants.verify(); RpcNameNodeService service = RpcNameNodeService.createInstance(CrailConstants.NAMENODE_RPC_SERVICE); RpcBinding rpcBinding = RpcBinding.createInstance(CrailConstants.NAMENODE_RPC_TYPE); rpcBinding.init(conf, null); rpcBinding.printConf(LOG); rpcBinding.run(service); System.exit(0); ; }
From source file:com.strider.appinv.agent.Scanner.java
public static void main(String[] args) throws ParseException, ScannerException { if (args.length == 0) { log.info("To display usage info please type"); log.info(" java -jar ai.jar com.strider.appinv.agent.Scanner --help"); return;/*from ww w. j a v a2 s .c o m*/ } final Options options = createOptions(); final CommandLine line = getCommandLine(options, args); if (line.hasOption("help")) { help(options); return; } if (line.hasOption("debug")) { LogManager.getRootLogger().setLevel(Level.DEBUG); } else { LogManager.getRootLogger().setLevel(Level.INFO); } String scannerPropertyFile = "scanner.properties"; if (line.hasOption("config")) { scannerPropertyFile = line.getOptionValue("config"); } Properties scannerProperties = null; try { scannerProperties = loadProperties(scannerPropertyFile); } catch (IOException ioe) { throw new ScannerException("ERROR: Unable to load " + scannerPropertyFile, ioe); } if (scannerProperties == null) { throw new ScannerException("ERROR: Scanner property file is not defined."); } IScanner scanner = new AppScanner(); Application application = null; if (line.hasOption("scan")) { scanner = new AppScanner(); application = scanner.scan(scannerProperties); } if (line.hasOption("persist") && application != null) { ApplicationUtils.save(application, scannerProperties.getProperty("scan.output.path")); } }