List of usage examples for org.apache.commons.cli HelpFormatter HelpFormatter
HelpFormatter
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 w w .j a v a 2s .c om 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.dasasian.chok.tool.ZkTool.java
public static void main(String[] args) { final Options options = new Options(); Option lsOption = new Option("ls", true, "list zp path contents"); lsOption.setArgName("path"); Option readOption = new Option("read", true, "read and print zp path contents"); readOption.setArgName("path"); Option rmOption = new Option("rm", true, "remove zk files"); rmOption.setArgName("path"); Option rmrOption = new Option("rmr", true, "remove zk directories"); rmrOption.setArgName("path"); OptionGroup actionGroup = new OptionGroup(); actionGroup.setRequired(true);//from www .j av a 2 s .c om actionGroup.addOption(lsOption); actionGroup.addOption(readOption); actionGroup.addOption(rmOption); actionGroup.addOption(rmrOption); options.addOptionGroup(actionGroup); final CommandLineParser parser = new GnuParser(); HelpFormatter formatter = new HelpFormatter(); try { final CommandLine line = parser.parse(options, args); ZkTool zkTool = new ZkTool(); if (line.hasOption(lsOption.getOpt())) { String path = line.getOptionValue(lsOption.getOpt()); zkTool.ls(path); } else if (line.hasOption(readOption.getOpt())) { String path = line.getOptionValue(readOption.getOpt()); zkTool.read(path); } else if (line.hasOption(rmOption.getOpt())) { String path = line.getOptionValue(rmOption.getOpt()); zkTool.rm(path, false); } else if (line.hasOption(rmrOption.getOpt())) { String path = line.getOptionValue(rmrOption.getOpt()); zkTool.rm(path, true); } zkTool.close(); } catch (ParseException e) { System.out.println(e.getClass().getSimpleName() + ": " + e.getMessage()); formatter.printHelp(ZkTool.class.getSimpleName(), options); } }
From source file:cloudnet.examples.evaluations.ConfigurableEvaluation.java
/** * @param args the command line arguments */// w ww .ja v a2s . c o m public static void main(String[] args) { Options options = makeOptions(); CommandLineParser parser = new DefaultParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("vmPlacementSimApp", options); return; } // apply options applyOptions(cmd); // run simulation runSimulation(); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); } // exit in order to stop R-Environment if it is used. System.exit(0); }
From source file:ca.uqac.info.trace.conversion.TraceConverter.java
/** * Main program loop/*w ww . j a va 2 s. c om*/ * @param args Command-line arguments */ @SuppressWarnings("static-access") public static void main(String[] args) { // Default values String input_format = "xml", output_format = "smv"; String input_filename = "trace.xml", output_filename = ""; //String event_tag_name = "Event"; // Define and process command line arguments Options options = new Options(); HelpFormatter help_formatter = new HelpFormatter(); Option opt; options.addOption("h", "help", false, "Show help"); opt = OptionBuilder.withArgName("format").hasArg() .withDescription("Input format for trace. Accepted values are csv, xml.").create("i"); opt.setRequired(false); options.addOption(opt); opt = OptionBuilder.withArgName("format").hasArg().withDescription( "Output format for trace. Accepted values are javamop, json, monpoly, smv, sql, xml. Default: smv") .create("t"); opt.setRequired(false); options.addOption(opt); opt = OptionBuilder.withArgName("filename").hasArg().withDescription("Input filename. Default: trace.xml") .create("f"); opt.setRequired(false); options.addOption(opt); opt = OptionBuilder.withArgName("filename").hasArg().withDescription("Output filename").create("o"); opt.setRequired(false); options.addOption(opt); opt = OptionBuilder.withArgName("name").hasArg().withDescription("Event tag name. Default: Event") .create("e"); opt.setRequired(false); options.addOption(opt); opt = OptionBuilder.withArgName("formula").hasArg().withDescription("Formula to translate").create("s"); opt.setRequired(false); options.addOption(opt); CommandLine c_line = parseCommandLine(options, args); if (c_line.hasOption("h")) { help_formatter.printHelp(app_name, options); System.exit(0); } input_filename = c_line.getOptionValue("f"); if (c_line.hasOption("o")) output_filename = c_line.getOptionValue("o"); /*if (c_line.hasOption("e")) event_tag_name = c_line.getOptionValue("e");*/ // Determine the input format if (!c_line.hasOption("i")) { // Guess output format by filename extension input_format = getExtension(input_filename); } if (c_line.hasOption("i")) { // The "t" parameter overrides the filename extension input_format = c_line.getOptionValue("i"); } // Determine which trace reader to initialize TraceReader reader = initializeReader(input_format); if (reader == null) { System.err.println("ERROR: Unrecognized input format"); System.exit(1); } // Instantiate the proper trace reader and checks that the trace exists //reader.setEventTagName(event_tag_name); File in_f = new File(input_filename); if (!in_f.exists()) { System.err.println("ERROR: Input file not found"); System.exit(1); } if (!in_f.canRead()) { System.err.println("ERROR: Input file is not readable"); System.exit(1); } // Determine the output format if (!c_line.hasOption("o") && !c_line.hasOption("t")) { System.err.println("ERROR: At least one of output filename and output format must be given"); System.exit(1); } if (c_line.hasOption("o")) { // Guess output format by filename extension output_filename = c_line.getOptionValue("o"); output_format = getExtension(output_filename); } if (c_line.hasOption("t")) { // The "t" parameter overrides the filename extension output_format = c_line.getOptionValue("t"); } // Determine which translator to initialize Translator trans = initializeTranslator(output_format); if (trans == null) { System.err.println("ERROR: Unrecognized output format"); System.exit(1); } // Translate the trace into the output format EventTrace trace = null; try { trace = reader.parseEventTrace(new FileInputStream(in_f)); } catch (FileNotFoundException ex) { ex.printStackTrace(); System.exit(1); } assert trace != null; trans.setTrace(trace); String out_trace = trans.translateTrace(); if (output_filename.isEmpty()) System.out.println(out_trace); else writeToFile(output_filename, out_trace); // Check if there is a formula to translate if (c_line.hasOption("s")) { String formula = c_line.getOptionValue("s"); try { Operator o = Operator.parseFromString(formula); trans.setFormula(o); System.out.println(trans.translateFormula()); } catch (Operator.ParseException e) { System.err.println("ERROR: parsing input formula"); System.exit(1); } } }
From source file:com.rapleaf.hank.cli.AddRingGroup.java
public static void main(String[] args) throws IOException, ParseException, InvalidConfigurationException { Options options = new Options(); options.addOption("r", "ring-group", true, "the name of the ring group to be created"); options.addOption("d", "domain-group", true, "the name of the domain group that this ring group will be linked to"); options.addOption("c", "config", true, "path of a valid config file with coordinator connection information"); try {// w w w . ja v a 2 s.c om CommandLine line = new GnuParser().parse(options, args); CommandLineChecker.check(line, options, new String[] { "config", "ring-group", "domain-group" }, AddRingGroup.class); ClientConfigurator configurator = new YamlClientConfigurator(line.getOptionValue("config")); addRingGroup(configurator, line.getOptionValue("ring-group"), line.getOptionValue("domain-group")); } catch (ParseException e) { new HelpFormatter().printHelp("add_domain", options); throw e; } }
From source file:com.jwm123.loggly.reporter.AppLauncher.java
public static void main(String args[]) throws Exception { try {/*from w w w.j a va 2 s . co m*/ CommandLine cl = parseCLI(args); try { config = new Configuration(); } catch (Exception e) { e.printStackTrace(); System.err.println("ERROR: Failed to read in persisted configuration."); } if (cl.hasOption("h")) { HelpFormatter help = new HelpFormatter(); String jarName = AppLauncher.class.getProtectionDomain().getCodeSource().getLocation().getFile(); if (jarName.contains("/")) { jarName = jarName.substring(jarName.lastIndexOf("/") + 1); } help.printHelp("java -jar " + jarName + " [options]", opts); } if (cl.hasOption("c")) { config.update(); } if (cl.hasOption("q")) { Client client = new Client(config); client.setQuery(cl.getOptionValue("q")); if (cl.hasOption("from")) { client.setFrom(cl.getOptionValue("from")); } if (cl.hasOption("to")) { client.setTo(cl.getOptionValue("to")); } List<Map<String, Object>> report = client.getReport(); if (report != null) { List<Map<String, String>> reportContent = new ArrayList<Map<String, String>>(); ReportGenerator generator = null; if (cl.hasOption("file")) { generator = new ReportGenerator(new File(cl.getOptionValue("file"))); } byte reportFile[] = null; if (cl.hasOption("g")) { System.out.println("Search results: " + report.size()); Set<Object> values = new TreeSet<Object>(); Map<Object, Integer> counts = new HashMap<Object, Integer>(); for (String groupBy : cl.getOptionValues("g")) { for (Map<String, Object> result : report) { if (mapContains(result, groupBy)) { Object value = mapGet(result, groupBy); values.add(value); if (counts.containsKey(value)) { counts.put(value, counts.get(value) + 1); } else { counts.put(value, 1); } } } System.out.println("For key: " + groupBy); for (Object value : values) { System.out.println(" " + value + ": " + counts.get(value)); } } if (cl.hasOption("file")) { Map<String, String> reportAddition = new LinkedHashMap<String, String>(); reportAddition.put("Month", MONTH_FORMAT.format(new Date())); reportContent.add(reportAddition); for (Object value : values) { reportAddition = new LinkedHashMap<String, String>(); reportAddition.put(value.toString(), "" + counts.get(value)); reportContent.add(reportAddition); } reportAddition = new LinkedHashMap<String, String>(); reportAddition.put("Total", "" + report.size()); reportContent.add(reportAddition); } } else { System.out.println("The Search [" + cl.getOptionValue("q") + "] yielded " + report.size() + " results."); if (cl.hasOption("file")) { Map<String, String> reportAddition = new LinkedHashMap<String, String>(); reportAddition.put("Month", MONTH_FORMAT.format(new Date())); reportContent.add(reportAddition); reportAddition = new LinkedHashMap<String, String>(); reportAddition.put("Count", "" + report.size()); reportContent.add(reportAddition); } } if (cl.hasOption("file")) { reportFile = generator.build(reportContent); File reportFileObj = new File(cl.getOptionValue("file")); FileUtils.writeByteArrayToFile(reportFileObj, reportFile); if (cl.hasOption("e")) { ReportMailer mailer = new ReportMailer(config, cl.getOptionValues("e"), cl.getOptionValue("s"), reportFileObj.getName(), reportFile); mailer.send(); } } } } } catch (IllegalArgumentException e) { System.err.println(e.getMessage()); System.exit(1); } }
From source file:gr.seab.r2rml.beans.Main.java
public static void main(String[] args) { Calendar c0 = Calendar.getInstance(); long t0 = c0.getTimeInMillis(); CommandLineParser cmdParser = new PosixParser(); Options cmdOptions = new Options(); cmdOptions.addOption("p", "properties", true, "define the properties file. Example: r2rml-parser -p r2rml.properties"); cmdOptions.addOption("h", "print help", false, "help"); String propertiesFile = "r2rml.properties"; try {// w w w. java2 s .com CommandLine line = cmdParser.parse(cmdOptions, args); if (line.hasOption("h")) { HelpFormatter help = new HelpFormatter(); help.printHelp("r2rml-parser\n", cmdOptions); System.exit(0); } if (line.hasOption("p")) { propertiesFile = line.getOptionValue("p"); } } catch (ParseException e1) { //e1.printStackTrace(); log.error("Error parsing command line arguments."); System.exit(1); } try { if (StringUtils.isNotEmpty(propertiesFile)) { properties.load(new FileInputStream(propertiesFile)); log.info("Loaded properties from " + propertiesFile); } } catch (FileNotFoundException e) { //e.printStackTrace(); log.error("Properties file not found (" + propertiesFile + ")."); System.exit(1); } catch (IOException e) { //e.printStackTrace(); log.error("Error reading properties file (" + propertiesFile + ")."); System.exit(1); } ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml"); Database db = (Database) context.getBean("db"); db.setProperties(properties); Parser parser = (Parser) context.getBean("parser"); parser.setProperties(properties); MappingDocument mappingDocument = parser.parse(); mappingDocument.getTimestamps().add(t0); //0 Started mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //1 Finished parsing. Starting generating result model. Generator generator = (Generator) context.getBean("generator"); generator.setProperties(properties); generator.setResultModel(parser.getResultModel()); //Actually do the output generator.createTriples(mappingDocument); context.close(); Calendar c1 = Calendar.getInstance(); long t1 = c1.getTimeInMillis(); log.info("Finished in " + (t1 - t0) + " milliseconds. Done."); mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //5 Finished. //log.info("5 Finished."); //output the result for (int i = 0; i < mappingDocument.getTimestamps().size(); i++) { if (i > 0) { long l = (mappingDocument.getTimestamps().get(i).longValue() - mappingDocument.getTimestamps().get(i - 1).longValue()); //System.out.println(l); log.info(String.valueOf(l)); } } log.info("Parse. Generate in memory. Dump to disk/database. Log. - Alltogether in " + String.valueOf(mappingDocument.getTimestamps().get(5).longValue() - mappingDocument.getTimestamps().get(0).longValue()) + " msec."); log.info("Done."); System.out.println("Done."); }
From source file:dyco4j.instrumentation.entry.CLI.java
public static void main(final String[] args) throws IOException { final Options _options = new Options(); _options.addOption(Option.builder().longOpt(IN_FOLDER_OPTION).required().hasArg() .desc("Folder containing the classes (as descendants) to be instrumented.").build()); _options.addOption(Option.builder().longOpt(OUT_FOLDER_OPTION).required().hasArg() .desc("Folder containing the classes (as descendants) with instrumentation.").build()); final String _msg = MessageFormat.format("Regex identifying the methods to be instrumented. Default: {0}.", METHOD_NAME_REGEX);//from w w w. j av a2s .c o m _options.addOption(Option.builder().longOpt(METHOD_NAME_REGEX_OPTION).hasArg(true).desc(_msg).build()); _options.addOption(Option.builder().longOpt(ONLY_ANNOTATED_TESTS_OPTION).hasArg(false) .desc("Instrument only tests identified by annotations.").build()); try { processCommandLine(new DefaultParser().parse(_options, args)); } catch (final ParseException _ex) { new HelpFormatter().printHelp(CLI.class.getName(), _options); } }
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(/*from www. ja v a 2s . co 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:demo.learn.shiro.tool.PasswordEncryptionTool.java
/** * Main method.// w ww . j a v a 2s .c o m * @param args Requires a plain text password. */ @SuppressWarnings("static-access") public static void main(String[] args) { String plainTextPassword = "root"; Option p = OptionBuilder.withArgName("password").hasArg().withDescription("plain text password") .isRequired(false).create('p'); Options options = new Options(); options.addOption(p); try { CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("p")) { plainTextPassword = cmd.getOptionValue("p"); } } catch (ParseException pe) { String cmdLineSyntax = "java -cp %CLASSPATH% demo.learn.shiro.tool.PasswordEncryptionTool"; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(cmdLineSyntax, options, false); return; } final RandomNumberGenerator rng = new SecureRandomNumberGenerator(); final ByteSource salt = rng.nextBytes(); final String saltBase64 = Base64.encodeToString(salt.getBytes()); final String hashedPasswordBase64 = new Sha256Hash(plainTextPassword, salt, S.HASH_ITER).toBase64(); System.out.print("-p " + plainTextPassword); System.out.print(" -h " + hashedPasswordBase64); System.out.println(" -s " + saltBase64); }