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:gov.lanl.adore.djatoka.DjatokaExtract.java
/** * Uses apache commons cli to parse input args. Passes parsed * parameters to IExtract implementation. * @param args command line parameters to defined input,output,etc. *//*www.j av a2 s .c o m*/ public static void main(String[] args) { // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption("i", "input", true, "Filepath of the input file."); options.addOption("o", "output", true, "Filepath of the output file."); options.addOption("l", "level", true, "Resolution level to extract."); options.addOption("d", "reduce", true, "Resolution levels to subtract from max resolution."); options.addOption("r", "region", true, "Format: Y,X,H,W. "); options.addOption("c", "cLayer", true, "Compositing Layer Index."); options.addOption("s", "scale", true, "Format: Option 1. Define a long-side dimension (e.g. 96); Option 2. Define absolute w,h values (e.g. 1024,768); Option 3. Define a single dimension (e.g. 1024,0) with or without Level Parameter; Option 4. Use a single decimal scaling factor (e.g. 0.854)"); options.addOption("t", "rotate", true, "Number of degrees to rotate image (i.e. 90, 180, 270)."); options.addOption("f", "format", true, "Mimetype of the image format to be provided as response. Default: image/jpeg"); options.addOption("a", "AltImpl", true, "Alternate IExtract Implemenation"); try { if (args.length == 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("gov.lanl.adore.djatoka.DjatokaExtract", options); System.exit(0); } // parse the command line arguments CommandLine line = parser.parse(options, args); String input = line.getOptionValue("i"); String output = line.getOptionValue("o"); DjatokaDecodeParam p = new DjatokaDecodeParam(); String level = line.getOptionValue("l"); if (level != null) p.setLevel(Integer.parseInt(level)); String reduce = line.getOptionValue("d"); if (level == null && reduce != null) p.setLevelReductionFactor(Integer.parseInt(reduce)); String region = line.getOptionValue("r"); if (region != null) p.setRegion(region); String cl = line.getOptionValue("c"); if (cl != null) { int clayer = Integer.parseInt(cl); if (clayer > 0) p.setCompositingLayer(clayer); } String scale = line.getOptionValue("s"); if (scale != null) { String[] v = scale.split(","); if (v.length == 1) { if (v[0].contains(".")) p.setScalingFactor(Double.parseDouble(v[0])); else { int[] dims = new int[] { -1, Integer.parseInt(v[0]) }; p.setScalingDimensions(dims); } } else if (v.length == 2) { int[] dims = new int[] { Integer.parseInt(v[0]), Integer.parseInt(v[1]) }; p.setScalingDimensions(dims); } } String rotate = line.getOptionValue("t"); if (rotate != null) p.setRotationDegree(Integer.parseInt(rotate)); String format = line.getOptionValue("f"); if (format == null) format = "image/jpeg"; String alt = line.getOptionValue("a"); if (output == null) output = input + ".jpg"; long x = System.currentTimeMillis(); IExtract ex = new KduExtractExe(); if (alt != null) ex = (IExtract) Class.forName(alt).newInstance(); DjatokaExtractProcessor e = new DjatokaExtractProcessor(ex); e.extractImage(input, output, p, format); logger.info("Extraction Time: " + ((double) (System.currentTimeMillis() - x) / 1000) + " seconds"); } catch (ParseException e) { logger.error("Parse exception:" + e.getMessage(), e); } catch (DjatokaException e) { logger.error("djatoka Extraction exception:" + e.getMessage(), e); } catch (InstantiationException e) { logger.error("Unable to initialize alternate implemenation:" + e.getMessage(), e); } catch (Exception e) { logger.error("Unexpected exception:" + e.getMessage(), e); } }
From source file:eu.annocultor.utils.XmlUtils.java
public static void main(String... args) throws Exception { // Handling command line parameters with Apache Commons CLI Options options = new Options(); options.addOption(OptionBuilder.withArgName(OPT_FN).hasArg().isRequired() .withDescription("XML file name to be pretty-printed").create(OPT_FN)); // now lets parse the input CommandLineParser parser = new BasicParser(); CommandLine cmd;/* ww w .j a v a 2 s . c o m*/ try { cmd = parser.parse(options, Utils.getCommandLineFromANNOCULTOR_ARGS(args)); } catch (ParseException pe) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pretty", options); return; } List<File> files = Utils.expandFileTemplateFrom(new File("."), cmd.getOptionValue(OPT_FN)); for (File file : files) { // XML pretty print System.out.println("Pretty-print for file " + file); if (file.exists()) prettyPrintXmlFileSAX(file.getCanonicalPath()); else throw new Exception("File not found: " + file.getCanonicalPath()); } }
From source file:com.svds.genericconsumer.main.GenericConsumerGroup.java
/** * Given command-line arguments, create GenericConsumerGroup * // www . j av a 2s . c o m * @param args command-line arguments to parse * @throws IOException */ public static void main(String[] args) throws IOException { LOG.info("HELLO from main"); Options options = new Options(); options.addOption(OptionBuilder.isRequired().withLongOpt(ZOOKEEPER).withDescription("Zookeeper servers") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(GROUPID).withDescription("Kafka group id").hasArg() .create()); options.addOption(OptionBuilder.isRequired().withLongOpt(TOPICNAME).withDescription("Kafka topic name") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(THREADS).withType(Number.class) .withDescription("Number of threads").hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(CONSUMERCLASS) .withDescription("Consumer Class from processing topic name").hasArg().create()); options.addOption(OptionBuilder.withLongOpt(PARAMETERS) .withDescription("Parameters needed for the consumer Class if needed").hasArgs() .withValueSeparator(',').create()); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { LOG.error(e.getMessage(), e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("GenericConsumerGroup.main", options); throw new IOException(e); } try { GenericConsumerGroup consumerGroupExample = new GenericConsumerGroup(); consumerGroupExample.doWork(cmd); } catch (ParseException ex) { LOG.error("Error parsing command-line args"); throw new IOException(ex); } }
From source file:me.preilly.SimplePush.java
public static void main(String[] args) throws Exception { /* Parse command line arguments */ Options opt = new Options(); opt.addOption("d", false, "Debug"); opt.addOption("e", true, "Environment to run in"); opt.addOption("h", false, "Print help for this application"); BasicParser parser = new BasicParser(); CommandLine cl = parser.parse(opt, args); boolean err = false; if (cl.hasOption("e")) { environmentKey = cl.getOptionValue("e"); }//from w w w . j a v a 2s. co m if (err || cl.hasOption("h")) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar SimplePush.jar -c cookie [-d -p -e [-f filename]]", opt); System.exit(0); } ConfigFactory factory = ConfigFactory.getInstance(); PropertiesConfiguration config = factory.getConfigProperties(environmentKey, propertiesFileName); Globals.getInstance(config); certName = config.getString(Const.CERT_NAME); certPass = config.getString(Const.CERT_PASSWORD); SimplePush obj = new SimplePush(); obj.pushMessage(); }
From source file:com.c4om.xsdfriendlyvalidator.XSDFriendlyValidatorLauncher.java
/** * Method called at application start./*from w w w . java2s.c o m*/ * * @param args command line args */ public static void main(String[] args) throws Exception { CommandLineParser parser = new BasicParser(); CommandLine commandLine1 = parser.parse(OPTIONS, args); CommandLine commandLine = commandLine1; if (commandLine.hasOption(OPTION_NAME_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(COMMAND_LINE_SYNTAX, OPTIONS); System.exit(0); } else if (!commandLine.hasOption(OPTION_NAME_INPUT_FILES)) { System.err.println("You must specify input files. Invoke with --help to see how."); System.exit(1); } String[] inputFileOptionValues = commandLine.getOptionValues(OPTION_NAME_INPUT_FILES); List<Document> inputFilesList = getListOfInputDocumentsFromCommandLine(inputFileOptionValues); String[] schemasOptionValues = commandLine.getOptionValues(OPTION_NAME_SCHEMAS); Map<String, Document> schemasMap = getSchemaFilesFromCommandLine(schemasOptionValues); XSDFriendlyValidator validator = new XSDFriendlyValidatorImpl(); ValidationResults validationResults = validator.validate(inputFilesList, Arrays.asList(inputFileOptionValues), schemasMap); System.out.println(validationResults.toString()); }
From source file:com.artofsolving.jodconverter.cli.ConvertDocument.java
public static void main(String[] arguments) throws Exception { CommandLineParser commandLineParser = new PosixParser(); CommandLine commandLine = commandLineParser.parse(OPTIONS, arguments); int port = SocketOpenOfficeConnection.DEFAULT_PORT; if (commandLine.hasOption(OPTION_PORT.getOpt())) { port = Integer.parseInt(commandLine.getOptionValue(OPTION_PORT.getOpt())); }/* w w w.jav a 2 s . c o m*/ String outputFormat = null; if (commandLine.hasOption(OPTION_OUTPUT_FORMAT.getOpt())) { outputFormat = commandLine.getOptionValue(OPTION_OUTPUT_FORMAT.getOpt()); } boolean verbose = false; if (commandLine.hasOption(OPTION_VERBOSE.getOpt())) { verbose = true; } DocumentFormatRegistry registry; if (commandLine.hasOption(OPTION_XML_REGISTRY.getOpt())) { File registryFile = new File(commandLine.getOptionValue(OPTION_XML_REGISTRY.getOpt())); if (!registryFile.isFile()) { System.err.println("ERROR: specified XML registry file not found: " + registryFile); System.exit(EXIT_CODE_XML_REGISTRY_NOT_FOUND); } registry = new XmlDocumentFormatRegistry(new FileInputStream(registryFile)); if (verbose) { System.out.println("-- loaded document format registry from " + registryFile); } } else { registry = new DefaultDocumentFormatRegistry(); } String[] fileNames = commandLine.getArgs(); if ((outputFormat == null && fileNames.length != 2) || fileNames.length < 1) { String syntax = "convert [options] input-file output-file; or\n" + "[options] -f output-format input-file [input-file...]"; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp(syntax, OPTIONS); System.exit(EXIT_CODE_TOO_FEW_ARGS); } OpenOfficeConnection connection = new SocketOpenOfficeConnection(port); try { if (verbose) { System.out.println("-- connecting to OpenOffice.org on port " + port); } connection.connect(); } catch (ConnectException officeNotRunning) { System.err.println( "ERROR: connection failed. Please make sure OpenOffice.org is running and listening on port " + port + "."); System.exit(EXIT_CODE_CONNECTION_FAILED); } try { DocumentConverter converter = new OpenOfficeDocumentConverter(connection, registry); if (outputFormat == null) { File inputFile = new File(fileNames[0]); File outputFile = new File(fileNames[1]); convertOne(converter, inputFile, outputFile, verbose); } else { for (int i = 0; i < fileNames.length; i++) { File inputFile = new File(fileNames[i]); File outputFile = new File(FilenameUtils.getFullPath(fileNames[i]) + FilenameUtils.getBaseName(fileNames[i]) + "." + outputFormat); convertOne(converter, inputFile, outputFile, verbose); } } } finally { if (verbose) { System.out.println("-- disconnecting"); } connection.disconnect(); } }
From source file:com.genentech.chemistry.tool.SDFFilter.java
public static void main(String args[]) { String usage = "java sdfFilter [options]\n" + "Filters out molecules that contain the following:\n" + "1. More than maxHeavy atoms (default is 100)\n" + "2. Have more than one component\n" + "3. Does not have any atoms\n" + "4. Have invalid atoms, like R, * etc ...\n" + "5. Have atomic number greater than 53 (Iodine)"; // create Options object Options options = new Options(); // add options options.addOption("h", false, ""); options.addOption("in", true, "inFile in OE formats: Ex: a.sdf or .sdf"); options.addOption("out", true, "outFile in OE formats. Ex: a.sdf or .sdf"); options.addOption("filtered", true, "Optional: filteredFile in OE formats. Ex: a.sdf or .sdf"); options.addOption("maxHeavy", true, "Number of heavy atom cutoff. Default is 100"); CommandLineParser parser = new PosixParser(); try {/*from w w w . ja v a2s .c om*/ CommandLine cmd = parser.parse(options, args); String inFile = cmd.getOptionValue("in"); if (inFile == null) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } String outFile = cmd.getOptionValue("out"); if (outFile == null) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } String filteredFile = null; if (cmd.hasOption("filtered")) { filteredFile = cmd.getOptionValue("filtered"); } int maxHeavy = 100; if (cmd.hasOption("maxHeavy")) { maxHeavy = Integer.parseInt(cmd.getOptionValue("maxHeavy")); maxAtoms = maxHeavy; } if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } oemolistream ifs = new oemolistream(inFile); oemolostream ofs = new oemolostream(outFile); oemolostream ffs = null; if (filteredFile != null) { ffs = new oemolostream(filteredFile); } /*it appears that we don't have license to molprop toolkit oeisstream iss = new oeisstream(); OEFilter filter = new OEFilter(iss); filter.SetTypeCheck(true); oechem.OEThrow.SetLevel(OEErrorLevel.Warning); */ OEGraphMol mol = new OEGraphMol(); while (oechem.OEReadMolecule(ifs, mol)) { // if (passFilters(mol, filter)) { //needs license to molprop toolkit if (passFilters(mol)) { oechem.OEWriteMolecule(ofs, mol); } else { if (ffs != null) { oechem.OEWriteMolecule(ffs, mol); } } } } catch (ParseException e) { // TODO print explaination throw new Error(e); } }
From source file:net.mybox.mybox.ServerSetup.java
/** * Handle command line arguments/* w w w . j a v a 2 s .c om*/ * @param args */ public static void main(String[] args) { Options options = new Options(); options.addOption("a", "apphome", true, "application home directory"); options.addOption("h", "help", false, "show help screen"); options.addOption("V", "version", false, "print the Mybox version"); CommandLineParser line = new GnuParser(); CommandLine cmd = null; try { cmd = line.parse(options, args); } catch (Exception exp) { System.err.println(exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(Server.class.getName(), options); return; } if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(Server.class.getName(), options); return; } if (cmd.hasOption("V")) { Server.printMessage("version " + Common.appVersion); return; } if (cmd.hasOption("a")) { String appHomeDir = cmd.getOptionValue("a"); try { Common.updatePaths(appHomeDir); } catch (FileNotFoundException e) { Server.printErrorExit(e.getMessage()); } Server.updatePaths(); } ServerSetup setup = new ServerSetup(); }
From source file:com.edduarte.argus.Main.java
public static void main(String[] args) { installUncaughtExceptionHandler();//from ww w . j a va 2s . c om CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption("t", "threads", true, "Number of threads to be used " + "for computation and indexing processes. Defaults to the number " + "of available cores."); options.addOption("p", "port", true, "Core server port. Defaults to 9000."); options.addOption("dbh", "db-host", true, "Database host. Defaults to localhost."); options.addOption("dbp", "db-port", true, "Database port. Defaults to 27017."); options.addOption("case", "preserve-case", false, "Keyword matching with case sensitivity."); options.addOption("stop", "stopwords", false, "Keyword matching with stopword filtering."); options.addOption("stem", "stemming", false, "Keyword matching with stemming (lexical variants)."); options.addOption("h", "help", false, "Shows this help prompt."); CommandLine commandLine; try { // Parse the program arguments commandLine = parser.parse(options, args); } catch (ParseException ex) { logger.error("There was a problem processing the input arguments. " + "Write -h or --help to show the list of available commands."); logger.error(ex.getMessage(), ex); return; } if (commandLine.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar argus-core.jar", options); return; } int maxThreads = Runtime.getRuntime().availableProcessors() - 1; maxThreads = maxThreads > 0 ? maxThreads : 1; if (commandLine.hasOption('t')) { String threadsText = commandLine.getOptionValue('t'); maxThreads = Integer.parseInt(threadsText); if (maxThreads <= 0 || maxThreads > 32) { logger.error("Invalid number of threads. Must be a number between 1 and 32."); return; } } int port = 9000; if (commandLine.hasOption('p')) { String portString = commandLine.getOptionValue('p'); port = Integer.parseInt(portString); } String dbHost = "localhost"; if (commandLine.hasOption("dbh")) { dbHost = commandLine.getOptionValue("dbh"); } int dbPort = 27017; if (commandLine.hasOption("dbp")) { String portString = commandLine.getOptionValue("dbp"); dbPort = Integer.parseInt(portString); } boolean isIgnoringCase = true; if (commandLine.hasOption("case")) { isIgnoringCase = false; } boolean isStoppingEnabled = false; if (commandLine.hasOption("stop")) { isStoppingEnabled = true; } boolean isStemmingEnabled = false; if (commandLine.hasOption("stem")) { isStemmingEnabled = true; } try { Context context = Context.getInstance(); context.setIgnoreCase(isIgnoringCase); context.setStopwordsEnabled(isStoppingEnabled); context.setStemmingEnabled(isStemmingEnabled); context.start(port, maxThreads, dbHost, dbPort); } catch (Exception ex) { ex.printStackTrace(); logger.info("Shutting down the server..."); System.exit(1); } }
From source file:com.edduarte.vokter.Main.java
public static void main(String[] args) { installUncaughtExceptionHandler();//from w w w . ja va 2 s .c o m CommandLineParser parser = new GnuParser(); Options options = new Options(); options.addOption("t", "threads", true, "Number of threads to be used " + "for computation and indexing processes. Defaults to the number " + "of available cores."); options.addOption("p", "port", true, "Core server port. Defaults to 9000."); options.addOption("dbh", "db-host", true, "Database host. Defaults to localhost."); options.addOption("dbp", "db-port", true, "Database port. Defaults to 27017."); options.addOption("case", "preserve-case", false, "Keyword matching with case sensitivity."); options.addOption("stop", "stopwords", false, "Keyword matching with stopword filtering."); options.addOption("stem", "stemming", false, "Keyword matching with stemming (lexical variants)."); options.addOption("h", "help", false, "Shows this help prompt."); CommandLine commandLine; try { // Parse the program arguments commandLine = parser.parse(options, args); } catch (ParseException ex) { logger.error("There was a problem processing the input arguments. " + "Write -h or --help to show the list of available commands."); logger.error(ex.getMessage(), ex); return; } if (commandLine.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar vokter-core.jar", options); return; } int maxThreads = Runtime.getRuntime().availableProcessors() - 1; maxThreads = maxThreads > 0 ? maxThreads : 1; if (commandLine.hasOption('t')) { String threadsText = commandLine.getOptionValue('t'); maxThreads = Integer.parseInt(threadsText); if (maxThreads <= 0 || maxThreads > 32) { logger.error("Invalid number of threads. Must be a number between 1 and 32."); return; } } int port = 9000; if (commandLine.hasOption('p')) { String portString = commandLine.getOptionValue('p'); port = Integer.parseInt(portString); } String dbHost = "localhost"; if (commandLine.hasOption("dbh")) { dbHost = commandLine.getOptionValue("dbh"); } int dbPort = 27017; if (commandLine.hasOption("dbp")) { String portString = commandLine.getOptionValue("dbp"); dbPort = Integer.parseInt(portString); } boolean isIgnoringCase = true; if (commandLine.hasOption("case")) { isIgnoringCase = false; } boolean isStoppingEnabled = false; if (commandLine.hasOption("stop")) { isStoppingEnabled = true; } boolean isStemmingEnabled = false; if (commandLine.hasOption("stem")) { isStemmingEnabled = true; } try { Context context = Context.getInstance(); context.setIgnoreCase(isIgnoringCase); context.setStopwordsEnabled(isStoppingEnabled); context.setStemmingEnabled(isStemmingEnabled); context.start(port, maxThreads, dbHost, dbPort); } catch (Exception ex) { ex.printStackTrace(); logger.info("Shutting down the server..."); System.exit(1); } }