List of usage examples for org.apache.commons.cli HelpFormatter printHelp
public void printHelp(String cmdLineSyntax, Options options)
options
with the specified command line syntax. 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;/* w ww .ja v a 2s . c o m*/ try { 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:io.proscript.jlight.JLight.java
public static void main(String[] args) throws IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); Option host = new Option("h", "host", true, "Host of the HTTP server (default 127.0.0.1)"); Option port = new Option("p", "port", true, "Port of the HTTP server (default 9000)"); Option main = new Option("c", "class", true, "Application to run, e.g. org.vendor.class"); Option help = new Option("h", "help", false, "Display help and exit"); Option version = new Option("v", "version", false, "Display JLight version"); options.addOption(host);/*w w w . ja v a 2s . c o m*/ options.addOption(port); options.addOption(main); options.addOption(help); options.addOption(version); CommandLine line; try { line = parser.parse(options, args); if (line.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); Version.print(); formatter.printHelp("jlight", options); return; } if (line.hasOption("v")) { Version.print(); return; } if (!line.hasOption("c")) { throw new ParseException("Option 'class' is required"); } Runtime.run(line); } catch (ParseException exp) { System.err.println(exp.getMessage()); } }
From source file:com.ctriposs.rest4j.tools.idlgen.Rest4JResourceModelExporterCmdLineApp.java
/** * @param args rest4jexporter -sourcepath sourcepath -resourcepackages packagenames [-name api_name] [-outdir outdir] *///from ww w . ja va2 s. c om public static void main(String[] args) { // args = new String[] {"-name", "groups", // "-resourcepackages", "com.ctriposs.groups.server.rest1.impl com.ctriposs.groups.server.rest2.impl ", // "-resourceclasses", "com.ctriposs.groups.server.restX.impl.FooResource", // "-sourcepath", "src/main/java", // "-outdir", "src/codegen/idl", // "-split"}; CommandLine cl = null; try { final CommandLineParser parser = new GnuParser(); cl = parser.parse(OPTIONS, args); } catch (ParseException e) { System.err.println("Invalid arguments: " + e.getMessage()); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "rest4jexporter -sourcepath sourcepath [-resourcepackages packagenames] [-resourceclasses classnames]" + "[-name api_name] [-outdir outdir]", OPTIONS); System.exit(0); } try { new Rest4JResourceModelExporter().export(cl.getOptionValue("name"), null, cl.getOptionValues("sourcepath"), cl.getOptionValues("resourcepackages"), cl.getOptionValues("resourceclasses"), cl.getOptionValue("outdir", ".")); } catch (Throwable e) { log.error("Error writing IDL files", e); System.exit(1); } }
From source file:de.uni_rostock.goodod.evaluator.EvaluatorApp.java
public static void main(String[] args) { Logger root = Logger.getRootLogger(); if (false == root.getAllAppenders().hasMoreElements()) { root.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN))); root.setLevel(Level.INFO); }/*from www. j av a 2s .co m*/ config = Configuration.getConfiguration(args); if (config.getBoolean("helpMode", false)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("evaluator [option]... <test_spec.plist | ontology1.owl ontology2.owl> ", config.getOptions()); System.exit(0); } if (config.getBoolean("debug", false)) { root.setLevel(Level.DEBUG); } OntologyTest theTest = null; String testFile = config.getString("testFile"); try { theTest = new OntologyTest(config.configurationAt("testDescription")); theTest.executeTest(); } catch (Throwable e) { logger.fatal("Fatal error", e); System.exit(1); } logger.info(theTest.toString()); String similarityType = config.getString("similarity"); String baseName = similarityType + "-" + testFile.substring(0, (testFile.length() - 6)); File precisionFile = null; File recallFile = null; File fmeasureFile = null; File similarityFile = null; precisionFile = new File(baseName + ".precision.csv"); recallFile = new File(baseName + ".recall.csv"); fmeasureFile = new File(baseName + ".fmeasure.csv"); similarityFile = new File(baseName + ".csv"); try { if (theTest.providesFMeasure()) { theTest.writePrecisionTable(new FileWriter(precisionFile)); theTest.writeRecallTable(new FileWriter(recallFile)); theTest.writeFMeasureTable(new FileWriter(fmeasureFile)); } else { theTest.writeSimilarityTable(new FileWriter(similarityFile)); } } catch (IOException e) { logger.warn("Could not write test data", e); } }
From source file:net.jingx.main.Main.java
/** * @param args//from ww w . j a va2 s .c o m * @throws IOException */ public static void main(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption(CLI_SECRET, true, "generate secret key (input is the configuration key from google)"); options.addOption(CLI_PASSCODE, true, "generate passcode (input is the secret key)"); options.addOption(new Option(CLI_HELP, "print this message")); try { CommandLine line = parser.parse(options, args); if (line.hasOption(CLI_SECRET)) { String confKey = line.getOptionValue(CLI_SECRET); String secret = generateSecret(confKey); System.out.println("Your secret to generate pins: " + secret); } else if (line.hasOption(CLI_PASSCODE)) { String secret = line.getOptionValue(CLI_PASSCODE); String pin = computePin(secret, null); System.out.println(pin); } else if (line.hasOption(CLI_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("GAuthCli", options); } else { EventQueue.invokeLater(new Runnable() { public void run() { try { MainGui window = new MainGui(); window.doSetVisible(); } catch (Exception e) { e.printStackTrace(); } } }); return; } System.out.println("Press any key to exit"); System.in.read(); } catch (Exception e) { System.out.println("Unexpected exception:" + e.getMessage()); } System.exit(0); }
From source file:edu.usc.pgroup.floe.client.commands.Scale.java
/** * Entry point for Scale command./*www. ja v a2s .c o m*/ * @param args command line arguments sent by the floe.py script. */ public static void main(final String[] args) { Options options = new Options(); Option dirOption = OptionBuilder.withArgName("direction").hasArg().isRequired() .withDescription("Scale Direction.").create("dir"); Option appOption = OptionBuilder.withArgName("name").hasArg().isRequired() .withDescription("Application Name").create("app"); Option pelletNameOption = OptionBuilder.withArgName("name").hasArg().isRequired() .withDescription("Pellet Name").create("pellet"); Option cntOption = OptionBuilder.withArgName("num").hasArg().withType(new String()) .withDescription("Number of instances to scale up/down").create("cnt"); options.addOption(dirOption); options.addOption(appOption); options.addOption(pelletNameOption); options.addOption(cntOption); CommandLineParser parser = new BasicParser(); CommandLine line; try { line = parser.parse(options, args); } catch (ParseException e) { LOGGER.error("Invalid command: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("scale options", options); return; } String dir = line.getOptionValue("dir"); String app = line.getOptionValue("app"); String pellet = line.getOptionValue("pellet"); String cnt = line.getOptionValue("cnt"); LOGGER.info("direction: {}", dir); LOGGER.info("Application: {}", app); LOGGER.info("Pellet: {}", pellet); LOGGER.info("count: {}", cnt); ScaleDirection direction = Enum.valueOf(ScaleDirection.class, dir); int count = Integer.parseInt(cnt); try { FloeClient.getInstance().getClient().scale(direction, app, pellet, count); } catch (TException e) { LOGGER.error("Error while connecting to the coordinator: {}", e); } }
From source file:Homework4Execute.java
/** * @param args/*from ww w . j av a 2s . com*/ */ public static void main(String[] args) { Parser parser = new GnuParser(); Options options = getCommandLineOptions(); String task = null; String host = null; String dir = null; CommandLine commandLine = null; try { commandLine = parser.parse(options, args); task = (String) commandLine.getOptionValue("task"); if ("traceroute".equals(task) || "cmdWinTrace".equals(task)) { host = (String) commandLine.getOptionValue("host"); if (host == null) { System.err.println("--host parameter required at this task!"); System.exit(-1); } } if ("cmdWinDir".equals(task)) { dir = (String) commandLine.getOptionValue("dir"); if (dir == null) { System.err.println("--dir parameter required at this task!"); System.exit(-1); } } } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar homework4execute.jar", options); System.exit(-1); } if (task != null) { switch (task) { case "enviroment": PrintEnviroment.printEnviroment(); break; case "traceroute": RedirectOutput2Pipe.traceroute(host); break; case "cmdWinTrace": ProcessBuilderExecute.cmdWinTrace(host); break; case "cmdWinDir": RuntimeExecute.cmdWinDir(dir); break; case "uname": RedirectOutput2File.getUname(); break; } } else { RunWithThread.executeCommand("javac Teszt.java"); RunWithThread.executeCommand("java -cp ./ Teszt"); } }
From source file:com.twitter.bazel.checkstyle.PythonCheckstyle.java
public static void main(String[] args) throws IOException { CommandLineParser parser = new DefaultParser(); // create the Options Options options = new Options(); options.addOption(Option.builder("f").required(true).hasArg().longOpt("extra_action_file") .desc("bazel extra action protobuf file").build()); options.addOption(Option.builder("p").required(true).hasArg().longOpt("pylint_file") .desc("Executable pylint file to invoke").build()); try {//from w ww.j ava 2s .c om // parse the command line arguments CommandLine line = parser.parse(options, args); String extraActionFile = line.getOptionValue("f"); String pylintFile = line.getOptionValue("p"); Collection<String> sourceFiles = getSourceFiles(extraActionFile); if (sourceFiles.size() == 0) { LOG.info("No python files found by checkstyle"); return; } LOG.info(sourceFiles.size() + " python files found by checkstyle"); // Create and run the command List<String> commandBuilder = new ArrayList<>(); commandBuilder.add(pylintFile); commandBuilder.addAll(sourceFiles); runLinter(commandBuilder); } catch (ParseException exp) { LOG.severe(String.format("Invalid input to %s: %s", CLASSNAME, exp.getMessage())); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java " + CLASSNAME, options); } }
From source file:com.boulmier.machinelearning.jobexecutor.JobExecutor.java
public static void main(String[] args) throws ParseException, IOException, InterruptedException { Options options = defineOptions();/* w ww . jav a 2 s . c om*/ sysMon = new JavaSysMon(); InetAddress vmscheduler_ip, mongodb_ip = null; Integer vmscheduler_port = null, mongodb_port = null; CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGPORTFIELD)) { vmscheduler_port = Integer.valueOf(cmd.getOptionValue(JobExecutorConfig.OPTIONS.CMD.LONGPORTFIELD)); } mongodb_port = (int) (cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGMONGOPORTFIELD) ? cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGMONGOPORTFIELD) : JobExecutorConfig.OPTIONS.LOGGING.MONGO_DEFAULT_PORT); mongodb_ip = InetAddress.getByName(cmd.getOptionValue(JobExecutorConfig.OPTIONS.CMD.LONGMONGOIPFIELD)); vmscheduler_ip = InetAddress.getByName(cmd.getOptionValue(JobExecutorConfig.OPTIONS.CMD.LONGIPFIELD)); decryptKey = cmd.getOptionValue("decrypt-key"); debugState = cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGDEBUGFIELD); logger = LoggerFactory.getLogger(); logger.info("Attempt to connect on master @" + vmscheduler_ip + ":" + vmscheduler_port); new RequestConsumer().start(); } catch (MissingOptionException moe) { logger.error(moe.getMissingOptions() + " are missing"); HelpFormatter help = new HelpFormatter(); help.printHelp(JobExecutor.class.getSimpleName(), options); } catch (UnknownHostException ex) { logger.error(ex.getMessage()); } finally { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { logger.info("JobExeutor is shutting down"); } }); } }
From source file:de.ncoder.studipsync.Starter.java
public static void main(String[] args) throws Exception { boolean displayHelp = false; CommandLineParser parser = new DefaultParser(); try {/*from ww w .j a v a 2 s . com*/ CommandLine cmd = parser.parse(OPTIONS, args); if (cmd.hasOption(OPTION_HELP)) { displayHelp = true; return; } Syncer syncer = createSyncer(cmd); StorageLog storeLog = new StorageLog(); syncer.getStorage().registerListener(storeLog); try { log.info("Started " + getImplementationTitle() + " " + getImplementationVersion()); syncer.sync(); log.info(storeLog.getStatusMessage(syncer.getStorage().getRoot())); log.info("Finished"); } finally { syncer.close(); } } catch (ParseException e) { System.out.println("Illegal arguments passed. " + e.getMessage()); displayHelp = true; } finally { if (displayHelp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("studip-sync", OPTIONS); } } //TODO AWT Event Queue blocks termination with modality level 1 System.exit(0); }