List of usage examples for org.apache.commons.cli OptionBuilder withDescription
public static OptionBuilder withDescription(String newDescription)
From source file:com.github.besherman.fingerprint.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withDescription("creates a fingerprint file for the directory").hasArg() .withArgName("dir").create('c')); options.addOption(OptionBuilder.withDescription("shows a diff between two fingerprint files") .withArgName("left-file> <right-file").hasArgs(2).create('d')); options.addOption(OptionBuilder.withDescription("shows a diff between a fingerprint and a directory") .withArgName("fingerprint> <dir").hasArgs(2).create('t')); options.addOption(OptionBuilder.withDescription("shows duplicates in a directory").withArgName("dir") .hasArgs(1).create('u')); options.addOption(// w w w . j a va2 s . c o m OptionBuilder.withDescription("output to file").withArgName("output-file").hasArg().create('o')); PosixParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException ex) { System.out.println(ex.getMessage()); System.out.println(""); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fingerprint-dir", options, true); System.exit(7); } if (cmd.hasOption('c')) { Path root = Paths.get(cmd.getOptionValue('c')); if (!Files.isDirectory(root)) { System.err.println("root is not a directory"); System.exit(7); } OutputStream out = System.out; if (cmd.hasOption('o')) { Path p = Paths.get(cmd.getOptionValue('o')); out = Files.newOutputStream(p); } Fingerprint fp = new Fingerprint(root, ""); fp.write(out); } else if (cmd.hasOption('d')) { String[] ar = cmd.getOptionValues('d'); Path leftFingerprintFile = Paths.get(ar[0]), rightFingerprintFile = Paths.get(ar[1]); if (!Files.isRegularFile(leftFingerprintFile)) { System.out.printf("%s is not a file%n", leftFingerprintFile); System.exit(7); } if (!Files.isRegularFile(rightFingerprintFile)) { System.out.printf("%s is not a file%n", rightFingerprintFile); System.exit(7); } Fingerprint left, right; try (InputStream input = Files.newInputStream(leftFingerprintFile)) { left = new Fingerprint(input); } try (InputStream input = Files.newInputStream(rightFingerprintFile)) { right = new Fingerprint(input); } Diff diff = new Diff(left, right); // TODO: if we have redirected output diff.print(System.out); } else if (cmd.hasOption('t')) { throw new RuntimeException("Not yet implemented"); } else if (cmd.hasOption('u')) { Path root = Paths.get(cmd.getOptionValue('u')); Fingerprint fp = new Fingerprint(root, ""); Map<String, FilePrint> map = new HashMap<>(); fp.stream().forEach(f -> { if (map.containsKey(f.getHash())) { System.out.println(" " + map.get(f.getHash()).getPath()); System.out.println("= " + f.getPath()); System.out.println(""); } else { map.put(f.getHash(), f); } }); } else { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fingd", options, true); } }
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();/*from w ww . jav a2 s. c o m*/ OptionBuilder.withArgName("PORT"); options.addOption(OptionBuilder.create("p")); OptionBuilder.withLongOpt("key"); OptionBuilder.withDescription("stop key"); OptionBuilder.hasArg(); 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();/* w ww . jav 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 ww w .j a v a2 s .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:com.happy_coding.viralo.coordinator.ViraloRunner.java
/** * Main task./*from w w w. j av a2 s. com*/ * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // Parser CommandLineParser parser = new PosixParser(); // Options Options options = new Options(); Option createFriends = OptionBuilder.withDescription("Create friends by using the given keywords.").hasArg() .withArgName("keywords").create("createFriends"); options.addOption(createFriends); options.addOption("R", "refreshFollowers", false, "refresh followers for current user."); options.addOption("C", "cleanup", false, "delete friends which don't follow"); options.addOption("S", "smartTweet", false, "Posts a smart tweet."); options.addOption("F", "createTrendFriends", false, "Create friends to a random trend."); options.addOption("T", "answerTopQuestion", false, "answer a top question and post it."); options.addOption("RC", "robotConversation", false, "starts a task which answers mentions automatically."); if (args.length < 1) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar ...jar", options); System.exit(0); } CommandLine line = parser.parse(options, args); if (line.hasOption("createFriends")) { String keywords = line.getOptionValue("createFriends"); Viralo viralo = new Viralo(); FriendDiscoverer friendDiscoverer = new FriendDiscoverer(); Contact forContact = friendDiscoverer.returnMyself(); System.out.println("Create friends for " + forContact.getName()); viralo.createNewFriends(forContact, keywords, ";"); } else if (line.hasOption("refreshFollowers")) { Viralo viralo = new Viralo(); FriendDiscoverer friendDiscoverer = new FriendDiscoverer(); Contact forContact = friendDiscoverer.returnMyself(); viralo.refreshFollowers(forContact); } else if (line.hasOption("cleanup")) { Viralo viralo = new Viralo(); FriendDiscoverer friendDiscoverer = new FriendDiscoverer(); Contact forContact = friendDiscoverer.returnMyself(); viralo.cleanup(forContact); } else if (line.hasOption("smartTweet")) { Viralo viralo = new Viralo(); viralo.postSmartTweet(); } else if (line.hasOption("createTrendFriends")) { FriendDiscoverer friendDiscoverer = new FriendDiscoverer(); Contact forContact = friendDiscoverer.returnMyself(); Viralo viralo = new Viralo(); viralo.createNewFriends(forContact); } else if (line.hasOption("answerTopQuestion")) { Viralo viralo = new Viralo(); viralo.answerTopQuestion(); } else if (line.hasOption("robotConversation")) { boolean taskFlag = true; Viralo viralo = new Viralo(); while (taskFlag) { /* reply to mentions */ viralo.autoConversation(); /* wait some seconds. */ Thread.sleep(WAIT_MS_BETWEEN_ACTIONS); } } System.exit(0); }
From source file:com.hurence.logisland.runner.SparkJobLauncher.java
/** * main entry point// w ww . j a v a 2s . co m * * @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: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(/* www .j ava 2s . co 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 .j a v a2 s. com*/ 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 w w w .jav 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(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(// w ww . j a va 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 = 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(); }