List of usage examples for org.apache.commons.cli CommandLine getOptionValue
public String getOptionValue(char opt)
From source file:com.dustindoloff.pngtastic.Main.java
public static void main(final String[] args) throws FileNotFoundException, IOException { final CommandLine commandLine = parseArgs(args); final String in = commandLine.getOptionValue(ARG_INPUT_PNG); final String out = commandLine.getOptionValue(ARG_OUTPUT_PNG); final String logLevel = commandLine.getOptionValue(ARG_LOG_LEVEL); final Integer iterations = toInteger(commandLine.getOptionValue(ARG_ITERATIONS)); final String compressor = commandLine.getOptionValue(ARG_COMPRESSOR); final Boolean removeGamma = Boolean.valueOf(commandLine.getOptionValue(ARG_REMOVE_GAMMA)); final Integer compressionLevel = toInteger(commandLine.getOptionValue(ARG_COMPRESSION_LEVEL)); final PngOptimizer pngOptimizer = new PngOptimizer(logLevel); pngOptimizer.setCompressor(compressor, iterations); final PngImage pngImage = new PngImage(in, logLevel); pngOptimizer.optimize(pngImage, out, removeGamma, compressionLevel); }
From source file:com.huangyunkun.jviff.Runner.java
public static void main(String args[]) { Options options = new Options(); options.addOption("c", "config", true, "config file"); CommandLineParser parser = new PosixParser(); try {/*from w ww .jav a2 s. c o m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("c")) { JViff jViff = new JViff(cmd.getOptionValue("c")); jViff.run(); } else { printHelp(options); } } catch (ParseException e) { printHelp(options); } catch (IOException e) { LOGGER.error("jviff face a error", e); } }
From source file:com.github.zerkseez.codegen.wrappergenerator.Main.java
public static void main(final String[] args) throws Exception { final Options options = new Options(); options.addOption(Option.builder().longOpt("outputDirectory").hasArg().required().build()); options.addOption(Option.builder().longOpt("classMappings").hasArgs().required().build()); final CommandLineParser parser = new DefaultParser(); try {//from w w w.j av a 2 s.co m final CommandLine line = parser.parse(options, args); final String outputDirectory = line.getOptionValue("outputDirectory"); final String[] classMappings = line.getOptionValues("classMappings"); for (String classMapping : classMappings) { final String[] tokens = classMapping.split(":"); if (tokens.length != 2) { throw new IllegalArgumentException( String.format("Invalid class mapping format \"%s\"", classMapping)); } final Class<?> wrappeeClass = Class.forName(tokens[0]); final String fullWrapperClassName = tokens[1]; final int indexOfLastDot = fullWrapperClassName.lastIndexOf('.'); final String wrapperPackageName = (indexOfLastDot == -1) ? "" : fullWrapperClassName.substring(0, indexOfLastDot); final String simpleWrapperClassName = (indexOfLastDot == -1) ? fullWrapperClassName : fullWrapperClassName.substring(indexOfLastDot + 1); System.out.println(String.format("Generating wrapper class for %s...", wrappeeClass)); final WrapperGenerator generator = new WrapperGenerator(wrappeeClass, wrapperPackageName, simpleWrapperClassName); generator.writeTo(outputDirectory, true); } System.out.println("Done"); } catch (MissingOptionException e) { final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(String.format("java -cp CLASSPATH %s", Main.class.getName()), options); } }
From source file:craterdog.security.DigitalNotaryMain.java
public static void main(String[] args) throws ParseException, IOException { HelpFormatter help = new HelpFormatter(); Options options = new Options(); options.addOption("help", false, "print this message"); options.addOption("pubfile", true, "public key input file"); options.addOption("prvfile", true, "private key input file"); try {// w w w.j a v a2s . c om CommandLine cli = new BasicParser().parse(options, args); String pubfile = cli.getOptionValue("pubfile"); String prvfile = cli.getOptionValue("prvfile"); NotaryKey notaryKey = notarization.generateNotaryKey(); if (pubfile != null || prvfile != null) { if (pubfile == null) throw new MissingArgumentException("Missing option: pubfile"); if (prvfile == null) throw new MissingArgumentException("Missing option: prvfile"); CertificateManager manager = new RsaCertificateManager(); PublicKey publicKey = manager.decodePublicKey(FileUtils.readFileToString(new File(pubfile))); char[] password = System.console().readPassword("input private key password: "); PrivateKey privateKey = manager.decodePrivateKey(FileUtils.readFileToString(new File(prvfile)), password); notaryKey.signingKey = privateKey; notaryKey.verificationKey = publicKey; // make sure it works DigitalSeal seal = notarization.notarizeDocument("test document", "test document", notaryKey); notarization.documentIsValid("test document", seal, publicKey); } char[] password = System.console().readPassword("verficationKey password: "); System.out.println(notarization.serializeNotaryKey(notaryKey, password)); } catch (MissingArgumentException | FileNotFoundException ex) { System.out.println(ex.getMessage()); help.printHelp(CMD_LINE_SYNTAX, options); System.exit(1); } }
From source file:io.github.sn0cr.rapidRunner.CommandlineInterface.java
public static void main(String[] args) { // create Options object final Options options = new Options(); // add t option // options.addOption("t", false, "display current time"); final CommandLineParser parser = new PosixParser(); try {//from w ww . j a va 2s . co m final CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("t")) { System.out.println("has option " + cmd.getOptionValue("t")); } else { System.out.println("hasn't option"); } } catch (final ParseException e) { e.printStackTrace(); } }
From source file:com.adobe.aem.demomachine.Base64Encoder.java
public static void main(String[] args) throws IOException { String value = null;/*from w ww. j a v a 2 s . c o m*/ // Command line options for this tool Options options = new Options(); options.addOption("v", true, "Value"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("v")) { value = cmd.getOptionValue("v"); } if (value == null) { System.out.println("Command line parameters: -v value"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } byte[] encodedBytes = Base64.encodeBase64(value.getBytes()); System.out.println(new String(encodedBytes)); }
From source file:com.twitter.bazel.checkstyle.JavaCheckstyle.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("c").required(true).hasArg().longOpt("checkstyle_config_file") .desc("checkstyle config file").build()); try {/* www . j av a2 s . c o m*/ // parse the command line arguments CommandLine line = parser.parse(options, args); String extraActionFile = line.getOptionValue("f"); String configFile = line.getOptionValue("c"); String[] sourceFiles = getSourceFiles(extraActionFile); if (sourceFiles.length == 0) { LOG.fine("No java files found by checkstyle"); return; } LOG.fine(sourceFiles.length + " java files found by checkstyle"); String[] checkstyleArgs = (String[]) ArrayUtils.addAll(new String[] { "-c", configFile }, sourceFiles); LOG.fine("checkstyle args: " + Joiner.on(" ").join(checkstyleArgs)); com.puppycrawl.tools.checkstyle.Main.main(checkstyleArgs); } 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.msbmsb.genealogeo.ui.cli.GenealoGeoCLI.java
/** * Command-line interface//w w w. ja va 2s.com */ public static void main(String[] args) throws Exception { GenealoGeoCLI cli = new GenealoGeoCLI(); // parse command line String inputFileName = ""; try { CommandLineParser parser = new GnuParser(); CommandLine cl = parser.parse(cli.opts, args); inputFileName = cl.getOptionValue("file"); if (cl.hasOption("help")) throw new ParseException(null); } catch (ParseException e) { cli.usage(e.getMessage()); } // require an input file if (inputFileName == null) { cli.usage("Error: No input file given."); } // verify and load the input file File inputFile = new File(inputFileName); if (!inputFile.exists()) { cli.usage("Error: Could not open input file: " + inputFileName); } cli.load(inputFile); // testing functions cli.genealoGeo.printFamilies(); cli.genealoGeo.printLocations(); }
From source file:com.octo.mbo.CopyNotes.java
public static void main(String[] args) throws JAXBException, IOException { try {// w w w . ja v a2 s. c o m CommandLine cli = parseCommandLine(args); final String srcFilePath = cli.getOptionValue("s"); final String targetFilePath = cli.getOptionValue("t"); //Dependency injection com.octo.mbo.io.Util util = new Util(); Loader loader = new Loader(new XmlPackageFactory(), new Pptx4jPackageFactory(), util); Processor processor = new Processor(new Merger(), loader, new SlideUpdator(), new XmlPackageFactory(), util); Orchestrator orchestrator = new Orchestrator(loader, processor); orchestrator.run(srcFilePath, targetFilePath, FileSystems.getDefault()); } catch (CommandLineException clex) { log.debug("Error parsing the command line. Please use CopyComment --help", clex); //Error messages are already printed by the parseCommandeLine() method log.error(clex.getMessage()); System.exit(-1); } catch (CopyNotesException ccex) { log.error("Internal error processing the document. Exiting", ccex); System.exit(-1); } }
From source file:graphgen.GraphGen.java
/** * @param args the command line arguments */// www . j av a 2 s . c o m public static void main(String[] args) { Options options = new Options(); HelpFormatter formatter = new HelpFormatter(); options.addOption(OPTION_EDGES, true, OPTION_EDGES_MSG); options.addOption(OPTION_NODES, true, OPTION_NODES_MSG); options.addOption(OPTION_OUTPUT, true, OPTION_OUTPUT_MSG); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); int edgeCount = Integer.valueOf(cmd.getOptionValue(OPTION_EDGES)); int nodeCount = Integer.valueOf(cmd.getOptionValue(OPTION_NODES)); String outputFile = cmd.getOptionValue(OPTION_OUTPUT); if ((nodeCount < edgeCount) || (outputFile != null)) { String graph = generateGraph(nodeCount, edgeCount); saveGraph(graph, outputFile); } else { formatter.printHelp(HELP_NAME, options); } } catch (NumberFormatException | ParseException e) { formatter.printHelp(HELP_NAME, options); } catch (IllegalArgumentException | FileNotFoundException e) { System.err.println(e.getMessage()); } }