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.asksunny.tool.Base64Tool.java
/** * @param args/*from www.j a va 2 s . c o m*/ */ public static void main(String[] args) throws Exception { Base64Tool base64 = new Base64Tool(); Options options = CLIOptionAnnotationBasedBinder.getOptions(base64); CLIOptionAnnotationBasedBinder.bindPosix(options, args, base64); if (base64.isHelp() || base64.isVersion() || base64.getPathToInput() == null || base64.getPathToOutput() == null) { HelpFormatter hfmt = new HelpFormatter(); hfmt.printHelp(base64.getClass().getName() + " <options>", options); if (base64.isHelp()) { System.exit(0); } else if (base64.isVersion()) { System.out.println(VERSION); System.exit(0); } else { System.exit(1); } } if (base64.isDecode()) { base64.decode(); } else { base64.encode(); } }
From source file:com.googlecode.hiberpcml.generator.Tool.java
public static void main(String arg[]) throws Exception { CommandLineParser parser = new PosixParser(); Options options = new Options(); Option destinyOpt = new Option("t", "target", true, "target of the generated classes"); destinyOpt.setArgName("target"); options.addOption(destinyOpt);/*from w w w . j av a 2 s . co m*/ Option packageOpt = new Option("p", "package", true, "Java Package of the generated classes"); packageOpt.setArgName("package"); options.addOption(packageOpt); Option webServiceOpt = new Option("w", "webservice", true, "build webservice classes"); webServiceOpt.setArgs(2); webServiceOpt.setArgName("serviceName service"); options.addOption(webServiceOpt); options.addOption(webServiceOpt); CommandLine cmd = parser.parse(options, arg); if (cmd.getArgs().length == 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("generator [options] FILE|DIRECTORY.", options); System.exit(1); } Pcml pcml; ArrayList<File> filesToParse = getFilesToParse(cmd.getArgs()[0]); JCodeModel cm = new JCodeModel(); JPackage _package = cm._package(cmd.getOptionValue("p", "")); Generator generator; WSGenerator wsGenerator = null; File targetFile = new File(cmd.getOptionValue("t", "./target")); targetFile.mkdirs(); if (cmd.hasOption("w")) { wsGenerator = new WSGenerator(_package, cmd.getOptionValues("w")[0], cmd.getOptionValues("w")[1]); } for (File file : filesToParse) { pcml = Util.load(file); if (cmd.hasOption("w")) { wsGenerator.addMethod(pcml); } else { generator = new Generator(); generator.generate(_package, pcml); } } cm.build(targetFile); }
From source file:cloudnet.examples.evaluations.ConfigurableEvaluation.java
/** * @param args the command line arguments */// ww w . j a v a 2 s.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:com.haulmont.mp2xls.MessagePropertiesProcessor.java
public static void main(String[] args) { Options options = new Options(); options.addOption(READ_OPT, "read", false, "read messages from project and save to XLS"); options.addOption(WRITE_OPT, "write", false, "load messages from XLS and write to project"); options.addOption(OVERWRITE_OPT, "overwrite", false, "overwrite existing messages by changed messages from XLS file"); options.addOption(PROJECT_DIR_OPT, "projectDir", true, "project root directory"); options.addOption(XLS_FILE_OPT, "xlsFile", true, "XLS file with translations"); options.addOption(LOG_FILE_OPT, "logFile", true, "log file"); options.addOption(LANGUAGES_OPT, "languages", true, "list of locales separated by comma, for example: 'de,fr'"); CommandLineParser parser = new DefaultParser(); CommandLine cmd;//from w w w. j a va 2 s .c o m try { cmd = parser.parse(options, args); if ((!cmd.hasOption(READ_OPT) && !cmd.hasOption(WRITE_OPT)) || !cmd.hasOption(PROJECT_DIR_OPT) || !cmd.hasOption(XLS_FILE_OPT) || !cmd.hasOption(LANGUAGES_OPT)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Messages To/From XLS Convertor", options); System.exit(-1); } if (cmd.hasOption(READ_OPT) && cmd.hasOption(WRITE_OPT)) { System.out.println("Please provide either 'read' or 'write' option"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Messages To/From XLS Convertor", options); System.exit(-1); } Set<String> languages = getLanguages(cmd.getOptionValue(LANGUAGES_OPT)); if (cmd.hasOption(READ_OPT)) { LocalizationsBatch localizationsBatch = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT)); localizationsBatch.setScanLocalizationIds(languages); LocalizationBatchExcelWriter.exportToXls(localizationsBatch, cmd.getOptionValue(XLS_FILE_OPT)); } else if (cmd.hasOption(WRITE_OPT)) { LocalizationsBatch sourceLocalization = new LocalizationsBatch(cmd.getOptionValue(PROJECT_DIR_OPT)); sourceLocalization.setScanLocalizationIds(languages); LocalizationsBatch fileLocalization = new LocalizationsBatch(cmd.getOptionValue(XLS_FILE_OPT), cmd.getOptionValue(PROJECT_DIR_OPT)); fileLocalization.setScanLocalizationIds(languages); LocalizationBatchFileWriter fileWriter = new LocalizationBatchFileWriter(sourceLocalization, fileLocalization); String logFile = StringUtils.isNotEmpty(cmd.getOptionValue(LOG_FILE_OPT)) ? cmd.getOptionValue(LOG_FILE_OPT) : "log.xls"; fileWriter.process(logFile, cmd.hasOption(OVERWRITE_OPT)); } } catch (Throwable e) { e.printStackTrace(); System.exit(-1); } }
From source file:cc.twittertools.corpus.demo.ReadStatuses.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input directory or file") .create(INPUT_OPTION));//from w w w . j a va 2s.c o m options.addOption(VERBOSE_OPTION, false, "print logging output every 10000 tweets"); options.addOption(DUMP_OPTION, false, "dump statuses"); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ReadStatuses.class.getName(), options); System.exit(-1); } PrintStream out = new PrintStream(System.out, true, "UTF-8"); StatusStream stream; // Figure out if we're reading from HTML SequenceFiles or JSON. File file = new File(cmdline.getOptionValue(INPUT_OPTION)); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } if (file.isDirectory()) { stream = new JsonStatusCorpusReader(file); } else { stream = new JsonStatusBlockReader(file); } int cnt = 0; Status status; while ((status = stream.next()) != null) { if (cmdline.hasOption(DUMP_OPTION)) { String text = status.getText(); if (text != null) { text = text.replaceAll("\\s+", " "); text = text.replaceAll("\0", ""); } out.println(String.format("%d\t%s\t%s\t%s", status.getId(), status.getScreenname(), status.getCreatedAt(), text)); } cnt++; if (cnt % 10000 == 0 && cmdline.hasOption(VERBOSE_OPTION)) { LOG.info(cnt + " statuses read"); } } stream.close(); LOG.info(String.format("Total of %s statuses read.", cnt)); }
From source file:de.htwg_konstanz.in.uce.hp.parallel.integration_test.TargetMock.java
public static void main(String[] args) throws IOException { CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); Option o = new Option("m", "mediatorIP", true, "mediator ip"); o.setRequired(true);/*from www . ja v a2 s .c om*/ options.addOption(o); o = new Option("p", "mediatorPort", true, "mediator port"); o.setRequired(true); options.addOption(o); o = new Option("t", "targetId", true, "target ID"); o.setRequired(true); options.addOption(o); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("TargetMock", options); return; } String mediatorIP = cmd.getOptionValue("mediatorIP"); String mediatorPort = cmd.getOptionValue("mediatorPort"); String targetId = cmd.getOptionValue("targetId"); InetSocketAddress mediatorSocketAddress; try { int port = Integer.parseInt(mediatorPort); mediatorSocketAddress = new InetSocketAddress(mediatorIP, port); } catch (NumberFormatException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } catch (IllegalArgumentException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } new TargetMock(mediatorSocketAddress, targetId).start(); }
From source file:io.wcm.devops.conga.tooling.cli.CongaCli.java
/** * CLI entry point/*from w ww . ja v a2 s.c o m*/ * @param args Command line arguments * @throws Exception */ //CHECKSTYLE:OFF public static void main(String[] args) throws Exception { //CHECKSTYLE:ON CommandLine commandLine = new DefaultParser().parse(CLI_OPTIONS, args); if (commandLine.hasOption("?")) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(150); formatter.printHelp("java -cp io.wcm.devops.conga.tooling.cli-<version>.jar " + "io.wcm.devops.conga.tooling.cli.CongaCli <arguments>", CLI_OPTIONS); return; } String templateDir = commandLine.getOptionValue("templateDir", "templates"); String roleDir = commandLine.getOptionValue("roleDir", "roles"); String environmentDir = commandLine.getOptionValue("environmentDir", "environments"); String targetDir = commandLine.getOptionValue("target", "target"); String[] environments = StringUtils.split(commandLine.getOptionValue("environments", null), ","); ResourceLoader resourceLoader = new ResourceLoader(); List<ResourceCollection> roleDirs = ImmutableList .of(resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + roleDir)); List<ResourceCollection> templateDirs = ImmutableList .of(resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + templateDir)); List<ResourceCollection> environmentDirs = ImmutableList .of(resourceLoader.getResourceCollection(ResourceLoader.FILE_PREFIX + environmentDir)); File targetDirecotry = new File(targetDir); Generator generator = new Generator(roleDirs, templateDirs, environmentDirs, targetDirecotry); generator.setDeleteBeforeGenerate(true); generator.generate(environments); }
From source file:de.l3s.content.mapred.WikipediaPagesBz2InputStream.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("gzipped XML dump file") .create(INPUT_OPTION));//from w w w .j a va 2 s . com options.addOption(OptionBuilder.withArgName("lang").hasArg().withDescription("output location") .create(LANGUAGE_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(WikipediaPagesBz2InputStream.class.getCanonicalName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String path = cmdline.getOptionValue(INPUT_OPTION); String lang = cmdline.hasOption(LANGUAGE_OPTION) ? cmdline.getOptionValue(LANGUAGE_OPTION) : "en"; WikipediaPage p = WikipediaPageFactory.createWikipediaPage(lang); WikipediaPagesBz2InputStream stream = new WikipediaPagesBz2InputStream(path); while (stream.readNext(p)) { System.out.println(p.getTitle() + "\t" + p.getDocid()); } }
From source file:cc.twittertools.util.ExtractSubcollection.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("dir").hasArg().withDescription("source collection directory") .create(COLLECTION_OPTION)); options.addOption(/* ww w . j a v a 2 s. c o m*/ OptionBuilder.withArgName("file").hasArg().withDescription("list of tweetids").create(ID_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(COLLECTION_OPTION) || !cmdline.hasOption(ID_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ExtractSubcollection.class.getName(), options); System.exit(-1); } String collectionPath = cmdline.getOptionValue(COLLECTION_OPTION); LongOpenHashSet tweetids = new LongOpenHashSet(); File tweetidsFile = new File(cmdline.getOptionValue(ID_OPTION)); if (!tweetidsFile.exists()) { System.err.println("Error: " + tweetidsFile + " does not exist!"); System.exit(-1); } LOG.info("Reading tweetids from " + tweetidsFile); FileInputStream fin = new FileInputStream(tweetidsFile); BufferedReader br = new BufferedReader(new InputStreamReader(fin)); String s; while ((s = br.readLine()) != null) { tweetids.add(Long.parseLong(s)); } br.close(); fin.close(); LOG.info("Read " + tweetids.size() + " tweetids."); File file = new File(collectionPath); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } PrintStream out = new PrintStream(System.out, true, "UTF-8"); StatusStream stream = new JsonStatusCorpusReader(file); Status status; while ((status = stream.next()) != null) { if (tweetids.contains(status.getId())) { out.println(status.getJsonObject().toString()); } } stream.close(); out.close(); }
From source file:jparser.JParser.java
/** * @param args the command line arguments *///ww w . j av a 2 s . c om public static void main(String[] args) { Options options = new Options(); CommandLineParser parser = new DefaultParser(); options.addOption( Option.builder().longOpt("to").desc("Indica el tipo de archivo al que debera convertir: JSON / XML") .hasArg().argName("tipo").build()); options.addOption(Option.builder().longOpt("path") .desc("Indica la ruta donde se encuentra el archivo origen").hasArg().argName("origen").build()); options.addOption( Option.builder().longOpt("target").desc("Indica la ruta donde se guardara el archivo resultante") .hasArg().argName("destino").build()); options.addOption("h", "help", false, "Muestra la guia de como usar la aplicacion"); try { CommandLine command = parser.parse(options, args); Path source = null; Path target = null; FactoryFileParse.TypeParce type = FactoryFileParse.TypeParce.NULL; Optional<Customer> customer = Optional.empty(); if (command.hasOption("h")) { HelpFormatter helper = new HelpFormatter(); helper.printHelp("JParser", options); System.exit(0); } if (command.hasOption("to")) type = FactoryFileParse.TypeParce.fromValue(command.getOptionValue("to", "")); if (command.hasOption("path")) source = Paths.get(command.getOptionValue("path", "")); if (command.hasOption("target")) target = Paths.get(command.getOptionValue("target", "")); switch (type) { case JSON: customer = FactoryFileParse.createNewInstance(FactoryFileParse.TypeParce.XML).read(source); break; case XML: customer = FactoryFileParse.createNewInstance(FactoryFileParse.TypeParce.JSON).read(source); break; } if (customer.isPresent()) { Customer c = customer.get(); boolean success = FactoryFileParse.createNewInstance(type).write(c, target); System.out.println(String.format("Operatation was: %s", success ? "success" : "fails")); } } catch (ParseException ex) { Logger.getLogger(JParser.class.getSimpleName()).log(Level.SEVERE, ex.getMessage(), ex); System.exit(-1); } }