List of usage examples for org.apache.commons.cli BasicParser BasicParser
BasicParser
From source file:edu.cuhk.hccl.cmd.AppQueryExpander.java
public static void main(String[] args) { try {//from ww w . jav a2s . c o m CommandLineParser parser = new BasicParser(); Options options = createOptions(); CommandLine line = parser.parse(options, args); // Get parameters String queryStr = line.getOptionValue('q'); int topK = Integer.parseInt(line.getOptionValue('k')); String modelPath = line.getOptionValue('m'); String queryType = line.getOptionValue('t'); QueryExpander expander = null; if (queryType.equalsIgnoreCase("WordVector")) { // Load word vectors System.out.println("[INFO] Loading word vectors..."); expander = new WordVectorExpander(modelPath); } else if (queryType.equalsIgnoreCase("WordNet")) { // Load WordNet System.out.println("[INFO] Loading WordNet..."); expander = new WordNetExpander(modelPath); } else { System.out.println("Please choose a correct expander: WordNet or WordVector!"); System.exit(-1); } // Expand query System.out.println("[INFO] Computing similar words..."); List<String> terms = expander.expandQuery(queryStr, topK); System.out.println(String.format("\n[INFO] The top %d similar words are: ", topK)); for (String term : terms) { System.out.println(term); } } catch (ParseException exp) { System.out.println("Error in parameters: \n" + exp.getMessage()); System.exit(-1); } }
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);/*ww w.j a v a2s . c o m*/ } 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:Compiler.java
/** A command line entry point to the mini Java compiler. *//*from www.j a v a 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.google.api.tools.framework.tools.configgen.ServiceConfigGeneratorTool.java
public static void main(String[] args) throws ParseException, IOException { ConfigGeneratorDriver.ensureStaticsInitialized(); ImmutableList<Option<?>> frameworkOptions = buildFrameworkOptions(); Options apacheCliOptions = ToolOptions.convertToApacheCliOptions(frameworkOptions); CommandLine cmd = (new BasicParser()).parse(apacheCliOptions, args); if (ToolOptions.isHelpFlagSet(cmd)) { ToolOptions.printUsage("ServiceConfigGeneratorTool", apacheCliOptions); System.exit(0);/*from ww w . j a va 2 s. co m*/ } ToolOptions toolOptions = ToolOptions.getToolOptionsFromCommandLine(cmd, frameworkOptions); System.exit(new ConfigGeneratorDriver(toolOptions).run()); }
From source file:com.discursive.jccook.cmdline.SomeApp.java
public static void main(String[] args) throws Exception { // Create a Parser 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 information"); OptionGroup optionGroup = new OptionGroup(); optionGroup.addOption(OptionBuilder.hasArg(true).withArgName("file").withLongOpt("file").create('f')); optionGroup.addOption(OptionBuilder.hasArg(true).withArgName("email").withLongOpt("email").create('m')); options.addOptionGroup(optionGroup); // Parse the program arguments try {// ww w. jav a 2 s . co m CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption('h')) { printUsage(options); System.exit(0); } // ... do important stuff ... } catch (Exception e) { System.out.println("You provided bad program arguments!"); printUsage(options); System.exit(1); } }
From source file:ezbake.thrift.VisibilityBase64Converter.java
public static void main(String[] args) { try {//from ww w . ja va 2 s. c om Options options = new Options(); options.addOption("d", "deserialize", false, "deserialize base64 visibility, if not present tool will serialize"); options.addOption("v", "visibility", true, "formalVisibility to serialize, or base64 encoded string to deserialize"); options.addOption("h", "help", false, "display usage info"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("thrift-visibility-converter", options); return; } String input = cmd.getOptionValue("v"); boolean deserialize = cmd.hasOption("d"); String output; if (deserialize) { if (input == null) { System.err.println("Cannot deserialize empty string"); System.exit(1); } output = ThriftUtils.deserializeFromBase64(Visibility.class, input).toString(); } else { Visibility visibility = new Visibility(); if (input == null) { input = "(empty visibility)"; } else { visibility.setFormalVisibility(input); } output = ThriftUtils.serializeToBase64(visibility); } String operation = deserialize ? "deserialize" : "serialize"; System.out.println("operation: " + operation); System.out.println("input: " + input); System.out.println("output: " + output); } catch (TException | ParseException e) { System.out.println("An error occurred: " + e.getMessage()); System.exit(1); } }
From source file:com.ardoq.mavenImport.ArdoqMavenImport.java
@SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { Options options = initOptions();// w ww . j av a2 s . com CommandLine cmd; try { CommandLineParser parser = new BasicParser(); cmd = parser.parse(options, args); if (cmd.hasOption("help")) { printHelp(options); return; } if (cmd.getArgList().isEmpty()) { System.out.println( "One or more Maven artifact IDs required. For instance: 'io.dropwizard:dropwizard-core:0.8.1'"); return; } String host = cmd.getOptionValue("h", "https://app.ardoq.com"); String token = cmd.getOptionValue("t"); String org = cmd.getOptionValue("o", "ardoq"); String workspace = cmd.getOptionValue("w"); List<String> importList = cmd.getArgList(); ArdoqMavenImport ardoqMavenImport = new ArdoqMavenImport(host, workspace, org, token); MavenUtil mavenUtil = new MavenUtil(System.out, "test", "provided"); if (cmd.hasOption("r")) { String extrarepo = cmd.getOptionValue("r"); if (cmd.hasOption("u") && cmd.hasOption("p")) { String username = cmd.getOptionValue("u"); String password = cmd.getOptionValue("p"); mavenUtil.addRepository(extrarepo, username, password); } else { mavenUtil.addRepository(extrarepo); } } ardoqMavenImport.startImport(importList, mavenUtil); } catch (MissingOptionException moe) { printHelp(options); } }
From source file:edu.ucsb.cs.eager.sa.cerebro.ProfessorX.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", "input-file", true, "Path to input xml file"); options.addOption("r", "root-path", true, "Root path of all Git repositories"); CommandLine cmd;// w ww . j av a 2 s.co m try { CommandLineParser parser = new BasicParser(); cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage() + "\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Cerebro", options); return; } String inputFileName = cmd.getOptionValue("i"); if (inputFileName == null) { System.err.println("input file path is required"); return; } String rootPath = cmd.getOptionValue("r"); if (rootPath == null) { System.err.println("root path is required"); return; } File inputFile = new File(inputFileName); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); Document doc; try { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); doc = dBuilder.parse(inputFile); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); return; } NodeList repoList = doc.getElementsByTagName("repo"); for (int i = 0; i < repoList.getLength(); i++) { Element repo = (Element) repoList.item(i); String name = repo.getElementsByTagName("name").item(0).getTextContent(); String classPath = repo.getElementsByTagName("classpath").item(0).getTextContent(); Set<String> classes = new LinkedHashSet<String>(); NodeList classesList = repo.getElementsByTagName("classes").item(0).getChildNodes(); for (int j = 0; j < classesList.getLength(); j++) { if (!(classesList.item(j) instanceof Element)) { continue; } classes.add(classesList.item(j).getTextContent()); } analyzeRepo(rootPath, name, classPath, classes); } }
From source file:com.crushpaper.Main.java
public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption("help", false, "print this message"); options.addOption("properties", true, "file system path to the crushpaper properties file"); // Parse the command line. CommandLineParser parser = new BasicParser(); CommandLine commandLine = null;//from w w w .j a v a 2s . c om try { commandLine = parser.parse(options, args); } catch (ParseException e) { System.err.println("crushpaper: Sorry, could not parse command line because `" + e.getMessage() + "`."); System.exit(1); } if (commandLine == null || commandLine.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("crushpaper", options); return; } // Get the properties path. String properties = null; if (commandLine.hasOption("properties")) { properties = commandLine.getOptionValue("properties"); } if (properties == null || properties.isEmpty()) { System.err.println("crushpaper: Sorry, the `properties` command argument must be specified."); System.exit(1); } Configuration configuration = new Configuration(); if (!configuration.load(new File(properties))) { System.exit(1); } // Get values. File databaseDirectory = configuration.getDatabaseDirectory(); File keyStorePath = configuration.getKeyStoreFile(); Integer httpPort = configuration.getHttpPort(); Integer httpsPort = configuration.getHttpsPort(); Integer httpsProxiedPort = configuration.getHttpsProxiedPort(); String keyStorePassword = configuration.getKeyStorePassword(); String keyManagerPassword = configuration.getKeyManagerPassword(); File temporaryDirectory = configuration.getTemporaryDirectory(); String singleUserName = configuration.getSingleUserName(); Boolean allowSelfSignUp = configuration.getAllowSelfSignUp(); Boolean allowSaveIfNotSignedIn = configuration.getAllowSaveIfNotSignedIn(); File logDirectory = configuration.getLogDirectory(); Boolean loopbackIsAdmin = configuration.getLoopbackIsAdmin(); File sessionStoreDirectory = configuration.getSessionStoreDirectory(); Boolean isOfficialSite = configuration.getIsOfficialSite(); File extraHeaderFile = configuration.getExtraHeaderFile(); // Validate the values. if (httpPort != null && httpsPort != null && httpPort.equals(httpsPort)) { System.err.println("crushpaper: Sorry, `" + configuration.getHttpPortKey() + "` and `" + configuration.getHttpsPortKey() + "` must not be set to the same value."); System.exit(1); } if ((httpsPort == null) != (keyStorePath == null)) { System.err.println("crushpaper: Sorry, `" + configuration.getHttpsPortKey() + "` and `" + configuration.getKeyStoreKey() + "` must either both be set or not set."); System.exit(1); } if (httpsProxiedPort != null && httpsPort == null) { System.err.println("crushpaper: Sorry, `" + configuration.getHttpsProxiedPortKey() + "` can only be set if `" + configuration.getHttpsPortKey() + "` is set."); System.exit(1); } if (databaseDirectory == null) { System.err.println("crushpaper: Sorry, `" + configuration.getDatabaseDirectoryKey() + "` must be set."); System.exit(1); } if (singleUserName != null && !AccountAttributeValidator.isUserNameValid(singleUserName)) { System.err.println( "crushpaper: Sorry, the username in `" + configuration.getSingleUserKey() + "` is not valid."); return; } if (allowSelfSignUp == null || allowSaveIfNotSignedIn == null || loopbackIsAdmin == null) { System.exit(1); } String extraHeader = null; if (extraHeaderFile != null) { extraHeader = readFile(extraHeaderFile); if (extraHeader == null) { System.err.println("crushpaper: Sorry, the file `" + extraHeaderFile.getPath() + "` set in `" + configuration.getExtraHeaderKey() + "` could not be read."); System.exit(1); } } final DbLogic dbLogic = new DbLogic(databaseDirectory); dbLogic.createDb(); final Servlet servlet = new Servlet(dbLogic, singleUserName, allowSelfSignUp, allowSaveIfNotSignedIn, loopbackIsAdmin, httpPort, httpsPort, httpsProxiedPort, keyStorePath, keyStorePassword, keyManagerPassword, temporaryDirectory, logDirectory, sessionStoreDirectory, isOfficialSite, extraHeader); servlet.run(); }
From source file:be.svlandeg.diffany.console.RunConsole.java
/** * Main method that allows running the Diffany algorithms through the console. * /*from w w w . j av a 2s . co m*/ * @param args the input arguments provided on the commandline */ public static void main(String[] args) { CommandLineParser parser = new BasicParser(); new RunConsole().runFromConsole(args, parser); }