List of usage examples for org.apache.commons.cli OptionBuilder hasArg
public static OptionBuilder hasArg()
From source file:com.aguin.stock.recommender.UserOptions.java
public static void main(String[] args) { options = new Options(); Option optU = OptionBuilder.hasArg().withArgName("uid").isRequired(true).withType(String.class) .withDescription(/*from www .j av a2s. c o m*/ "User ID : must be a valid email address which serves as the unique identity of the portfolio") .create("u"); Option optI = OptionBuilder.hasOptionalArgs().withArgName("item").withType(String.class).isRequired(false) .withDescription( "Stock(s) in your portfolio: Print all stocks selected by this option and preferences against them") .create("i"); Option optP = OptionBuilder.hasOptionalArgs().withArgName("pref").isRequired(false).withType(Long.class) .withDescription( "Preference(s) against stocks in portfolio : Print all preferences specified in option and all stocks listed against that preference. Multiple preferences may be specified to draw on the many-many relationship between stocks and preferences matrices") .create("p"); Option optIP = OptionBuilder.hasArg().withArgName("itempref").withValueSeparator(':').isRequired(false) .withDescription( "Enter stock and preferences over command line. Any new stock will be registered as a new entry along with preference. Each new preference for an already existing stock will overwrite the existing preference(so be careful!)") .create("ip"); Option optF = OptionBuilder.hasArg().withArgName("itempreffile").withType(String.class) .withDescription("File to read stock preference data from").isRequired(false).create("f"); Option optH = OptionBuilder.hasArg(false).withArgName("help").withType(String.class) .withDescription("Display usage").isRequired(false).create("h"); options.addOption(optU); options.addOption(optI); options.addOption(optP); options.addOption(optIP); options.addOption(optF); options.addOption(optH); parser = new BasicParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (MissingOptionException e) { System.out.println("Missing options"); printUsage(); } catch (ParseException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } if (line.hasOption("help")) { printUsage(); } UserArgumentEmailType uEmailId = new UserArgumentEmailType(line.getOptionValue("u")); String uEmailIdStr = uEmailId.toString(); if (MongoDBUserModel.registered(uEmailIdStr)) { System.out.format("Already registered user %s\n", uEmailIdStr); } else { System.out.format("+--Starting transaction for user %s --+\n", uEmailIdStr); } if (line.hasOption("f")) { System.out.println("Query::UpdateDB: itempreffile(s)\n"); String[] uItemPrefFiles = line.getOptionValues("f"); for (String it : uItemPrefFiles) { System.out.format("Updating db with user file %s\n", it); UserItemPrefFile uItemPrefFile = new UserItemPrefFile(uEmailIdStr, it); uItemPrefFile.writeToDB(); } } if (line.hasOption("i")) { System.out.println("Query::ReadDB: item(s)\n"); String[] uItems = line.getOptionValues("i"); for (String it : uItems) { System.out.format("Searching for item %s in db\n", it); UserItem uItem = new UserItem(uEmailIdStr, it); uItem.readFromDB(); } } if (line.hasOption("p")) { System.out.println("Query::ReadDB: preference(s)"); String[] uPrefs = line.getOptionValues("p"); for (String it : uPrefs) { System.out.format("Searching for preference %s in db\n", it); UserPreference uPref = new UserPreference(uEmailIdStr, it); uPref.readFromDB(); } } if (line.hasOption("ip")) { System.out.println("Query::UpdateDB: itempref(s)\n"); String[] uItemPrefs = line.getOptionValues("ip"); for (String it : uItemPrefs) { System.out.format("Updating item:preference pair %s\n", it); String[] pair = it.split(":"); System.out.format("%s:%s:%s", uEmailIdStr, pair[0], pair[1]); UserItemPreference uItemPref = new UserItemPreference(uEmailIdStr, pair[0], pair[1]); uItemPref.writeToDB(); } } System.out.format("+-- Ending transaction for user %s --+\n", uEmailIdStr); }
From source file:RedPenRunner.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "help"); options.addOption("v", "version", false, "print the version information and exit"); OptionBuilder.withLongOpt("port"); OptionBuilder.withDescription("port number"); OptionBuilder.hasArg(); OptionBuilder.withArgName("PORT"); options.addOption(OptionBuilder.create("p")); OptionBuilder.withLongOpt("key"); OptionBuilder.withDescription("stop key"); OptionBuilder.hasArg();// w ww . ja v a2 s. co m OptionBuilder.withArgName("STOP_KEY"); options.addOption(OptionBuilder.create("k")); OptionBuilder.withLongOpt("conf"); OptionBuilder.withDescription("configuration file"); OptionBuilder.hasArg(); OptionBuilder.withArgName("CONFIG_FILE"); options.addOption(OptionBuilder.create("c")); OptionBuilder.withLongOpt("lang"); OptionBuilder.withDescription("Language of error messages"); OptionBuilder.hasArg(); OptionBuilder.withArgName("LANGUAGE"); options.addOption(OptionBuilder.create("L")); CommandLineParser parser = new BasicParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (Exception e) { printHelp(options); System.exit(-1); } int portNum = 8080; String language = "en"; if (commandLine.hasOption("h")) { printHelp(options); System.exit(0); } if (commandLine.hasOption("v")) { System.out.println(RedPen.VERSION); System.exit(0); } if (commandLine.hasOption("p")) { portNum = Integer.parseInt(commandLine.getOptionValue("p")); } if (commandLine.hasOption("L")) { language = commandLine.getOptionValue("L"); } if (isPortTaken(portNum)) { System.err.println("port is taken..."); System.exit(1); } // set language if (language.equals("ja")) { Locale.setDefault(new Locale("ja", "JA")); } else { Locale.setDefault(new Locale("en", "EN")); } final String contextPath = System.getProperty("redpen.home", "/"); Server server = new Server(portNum); ProtectionDomain domain = RedPenRunner.class.getProtectionDomain(); URL location = domain.getCodeSource().getLocation(); HandlerList handlerList = new HandlerList(); if (commandLine.hasOption("key")) { // Add Shutdown handler only when STOP_KEY is specified ShutdownHandler shutdownHandler = new ShutdownHandler(commandLine.getOptionValue("key")); handlerList.addHandler(shutdownHandler); } WebAppContext webapp = new WebAppContext(); webapp.setContextPath(contextPath); if (location.toExternalForm().endsWith("redpen-server/target/classes/")) { // use redpen-server/target/redpen-server instead, because target/classes doesn't contain web resources. webapp.setWar(location.toExternalForm() + "../redpen-server/"); } else { webapp.setWar(location.toExternalForm()); } if (commandLine.hasOption("c")) { webapp.setInitParameter("redpen.conf.path", commandLine.getOptionValue("c")); } handlerList.addHandler(webapp); server.setHandler(handlerList); server.start(); server.join(); }
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(); OptionBuilder.isRequired();/*w w w.j a va 2 s. c o m*/ 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(); OptionBuilder.isRequired();//from w w w.j a va 2 s .c o m 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:fr.tpt.atlanalyser.tests.TestOldAGTExpPost2Pre.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // URL resource = Thread.currentThread().getContextClassLoader() // .getResource("OldAGTExp"); // System.out.println(resource.toString()); // File f = new File(resource.getPath()); // System.out.println(f.toString()); // System.out.println(f.isDirectory()); // System.exit(0); Options options = new Options(); options.addOption(//ww w .jav a 2 s . c o m OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j")); options.addOption(OptionBuilder.withDescription("Display help").create("h")); CommandLineParser parser = new BasicParser(); int jobs = 1; try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { new HelpFormatter().printHelp(TestOldAGTExpPost2Pre.class.getSimpleName(), options); System.exit(0); } if (cmd.hasOption("j")) { jobs = Integer.parseInt(cmd.getOptionValue("j")); } } catch (Exception e) { System.out.println("Incorrect command line arguments"); new HelpFormatter().printHelp(TestOldAGTExpPost2Pre.class.getSimpleName(), options); System.exit(1); } new TestOldAGTExpPost2Pre(models().iterator().next()[0], jobs).testPost2Pre(); }
From source file:fr.tpt.atlanalyser.tests.TestForPaperPost2Pre.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // URL resource = Thread.currentThread().getContextClassLoader() // .getResource("OldAGTExp"); // System.out.println(resource.toString()); // File f = new File(resource.getPath()); // System.out.println(f.toString()); // System.out.println(f.isDirectory()); // System.exit(0); Options options = new Options(); options.addOption(//from ww w . ja v a2 s. c o m OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j")); options.addOption(OptionBuilder.withDescription("Display help").create("h")); CommandLineParser parser = new BasicParser(); int jobs = 1; try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { new HelpFormatter().printHelp(TestForPaperPost2Pre.class.getSimpleName(), options); System.exit(0); } if (cmd.hasOption("j")) { jobs = Integer.parseInt(cmd.getOptionValue("j")); } } catch (Exception e) { System.out.println("Incorrect command line arguments"); new HelpFormatter().printHelp(TestForPaperPost2Pre.class.getSimpleName(), options); System.exit(1); } new TestForPaperPost2Pre(models().get(0)[0], jobs).testPost2Pre(); }
From source file:fr.tpt.atlanalyser.tests.TestPointsToLinesPost2Pre.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // URL resource = Thread.currentThread().getContextClassLoader() // .getResource("OldAGTExp"); // System.out.println(resource.toString()); // File f = new File(resource.getPath()); // System.out.println(f.toString()); // System.out.println(f.isDirectory()); // System.exit(0); Options options = new Options(); options.addOption(//from ww w . j a v a 2s . c o m OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j")); options.addOption(OptionBuilder.withDescription("Display help").create("h")); CommandLineParser parser = new BasicParser(); int jobs = 1; try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { new HelpFormatter().printHelp(TestPointsToLinesPost2Pre.class.getSimpleName(), options); System.exit(0); } if (cmd.hasOption("j")) { jobs = Integer.parseInt(cmd.getOptionValue("j")); } } catch (Exception e) { System.out.println("Incorrect command line arguments"); new HelpFormatter().printHelp(TestPointsToLinesPost2Pre.class.getSimpleName(), options); System.exit(1); } new TestPointsToLinesPost2Pre(models().get(1)[0], jobs).testPost2Pre(); }
From source file:fr.tpt.atlanalyser.tests.TestClass2RelationalPost2Pre.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // URL resource = Thread.currentThread().getContextClassLoader() // .getResource("OldAGTExp"); // System.out.println(resource.toString()); // File f = new File(resource.getPath()); // System.out.println(f.toString()); // System.out.println(f.isDirectory()); // System.exit(0); Options options = new Options(); options.addOption(//from w w w . java 2s. c o m OptionBuilder.hasArg().withArgName("N").withDescription("Number of parallel jobs").create("j")); options.addOption(OptionBuilder.withDescription("Display help").create("h")); CommandLineParser parser = new BasicParser(); int jobs = 2; try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { new HelpFormatter().printHelp(TestClass2RelationalPost2Pre.class.getSimpleName(), options); System.exit(0); } if (cmd.hasOption("j")) { jobs = Integer.parseInt(cmd.getOptionValue("j")); } } catch (Exception e) { System.out.println("Incorrect command line arguments"); new HelpFormatter().printHelp(TestClass2RelationalPost2Pre.class.getSimpleName(), options); System.exit(1); } new TestClass2RelationalPost2Pre(models().get(0)[0], jobs).testPost2Pre(); }
From source file:com.hurence.logisland.runner.SparkJobLauncher.java
/** * main entry point//from ww w .j a v a2 s .c om * * @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:name.wagners.fssp.Main.java
/** * @param args/*ww w . j a va2 s . c o m*/ * command-line arguments */ public static void main(final String[] args) { // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption(OptionBuilder.hasArg().withArgName("gn").withLongOpt("generations") .withDescription("Number of generations [default: 50]").withType(Integer.valueOf(0)).create("g")); options.addOption(OptionBuilder.hasArg().withArgName("mp").withLongOpt("mutation") .withDescription("Mutation propability [default: 0.5]").withType(Double.valueOf(0)).create("m")); options.addOption(OptionBuilder.hasArg().withArgName("ps").withLongOpt("populationsize") .withDescription("Size of population [default: 20]").withType(Integer.valueOf(0)).create("p")); options.addOption(OptionBuilder.hasArg().withArgName("rp").withLongOpt("recombination") .withDescription("Recombination propability [default: 0.8]").withType(Double.valueOf(0)) .create("r")); options.addOption(OptionBuilder.hasArg().withArgName("sp").withLongOpt("selectionpressure") .withDescription("Selection pressure [default: 4]").withType(Integer.valueOf(0)).create("s")); options.addOption(OptionBuilder.withLongOpt("help").withDescription("print this message").create("h")); options.addOption(OptionBuilder.hasArg().withArgName("filename").isRequired().withLongOpt("file") .withDescription("Problem file [default: \"\"]").withType(String.valueOf("")).create("f")); options.addOptionGroup(new OptionGroup() .addOption(OptionBuilder.withLongOpt("verbose").withDescription("be extra verbose").create("v")) .addOption(OptionBuilder.withLongOpt("quiet").withDescription("be extra quiet").create("q"))); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("print the version information and exit").create("V")); try { // parse the command line arguments CommandLine line = parser.parse(options, args); // validate that block-size has been set if (line.hasOption("h")) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } } catch (MissingOptionException exp) { log.info("An option was missing:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } catch (MissingArgumentException exp) { log.info("An argument was missing:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } catch (AlreadySelectedException exp) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } catch (ParseException exp) { log.info("Unexpected exception:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); System.exit(1); } // Ausgabe der eingestellten Optionen log.info("Configuration"); // log.info(" Datafile: {}", fname); }