List of usage examples for org.apache.commons.cli Option getLongOpt
public String getLongOpt()
From source file:com.databasepreservation.cli.CLI.java
private static String getUniqueOptionIdentifier(Option option) { // some string that should never occur in option shortName nor longName final String delimiter = "\r\f\n"; return new StringBuilder().append(delimiter).append(option.getOpt()).append(delimiter) .append(option.getLongOpt()).append(delimiter).toString(); }
From source file:at.ac.tuwien.ims.latex2mobiformulaconv.app.Main.java
private static void parseCli(String[] args) { CommandLineParser parser = new PosixParser(); try {//from ww w . j a v a2 s . c o m CommandLine cmd = parser.parse(options, args); // Show usage, ignore other parameters and quit if (cmd.hasOption('h')) { usage(); logger.debug("Help called, main() exit."); System.exit(0); } if (cmd.hasOption('d')) { // Activate debug markup only - does not affect logging! debugMarkupOutput = true; } if (cmd.hasOption('m')) { exportMarkup = true; } if (cmd.hasOption('t')) { title = cmd.getOptionValue('t'); } if (cmd.hasOption('f')) { filename = cmd.getOptionValue('f'); } if (cmd.hasOption('n')) { exportMarkup = true; // implicit markup export noMobiConversion = true; } if (cmd.hasOption('i')) { String[] inputValues = cmd.getOptionValues('i'); for (String inputValue : inputValues) { inputPaths.add(Paths.get(inputValue)); } } else { logger.error("You have to specify an inputPath file or directory!"); usage(); System.exit(1); } if (cmd.hasOption('o')) { String outputDirectory = cmd.getOptionValue('o'); outputPath = Paths.get(outputDirectory).toAbsolutePath(); logger.debug("Output path: " + outputPath.toAbsolutePath().toString()); if (!Files.isDirectory(outputPath) && Files.isRegularFile(outputPath)) { logger.error("Given output directory is a file! Exiting..."); System.exit(1); } if (!Files.exists(outputPath)) { Files.createDirectory(outputPath); } if (!Files.isWritable(outputPath)) { logger.error("Given output directory is not writable! Exiting..."); logger.debug(outputPath.toAbsolutePath().toString()); System.exit(1); } logger.debug("Output path: " + outputPath.toAbsolutePath().toString()); } else { // Set default output directory if none is given outputPath = workingDirectory; } // If set, replace LaTeX Formulas with PNG images, created by if (cmd.hasOption("r")) { logger.debug("Picture Flag set"); replaceWithPictures = true; } if (cmd.hasOption("u")) { logger.debug("Use calibre instead of kindlegen"); useCalibreInsteadOfKindleGen = true; } // Executable configuration LatexToHtmlConverter latexToHtmlConverter = (LatexToHtmlConverter) applicationContext .getBean("latex2html-converter"); if (cmd.hasOption(latexToHtmlConverter.getExecOption().getOpt())) { String execValue = cmd.getOptionValue(latexToHtmlConverter.getExecOption().getOpt()); logger.info("LaTeX to HTML Executable argument was given: " + execValue); Path execPath = Paths.get(execValue); latexToHtmlConverter.setExecPath(execPath); } String htmlToMobiConverterBean = KINDLEGEN_HTML2MOBI_CONVERTER; if (useCalibreInsteadOfKindleGen) { htmlToMobiConverterBean = CALIBRE_HTML2MOBI_CONVERTER; } HtmlToMobiConverter htmlToMobiConverter = (HtmlToMobiConverter) applicationContext .getBean(htmlToMobiConverterBean); Option htmlToMobiOption = htmlToMobiConverter.getExecOption(); if (cmd.hasOption(htmlToMobiOption.getOpt())) { String execValue = cmd.getOptionValue(htmlToMobiOption.getOpt()); logger.info("HTML to Mobi Executable argument was given: " + execValue); try { Path execPath = Paths.get(execValue); htmlToMobiConverter.setExecPath(execPath); } catch (InvalidPathException e) { logger.error("Invalid path given for --" + htmlToMobiOption.getLongOpt() + " <" + htmlToMobiOption.getArgName() + ">"); logger.error("I will try to use your system's PATH variable..."); } } } catch (MissingOptionException m) { Iterator<String> missingOptionsIterator = m.getMissingOptions().iterator(); while (missingOptionsIterator.hasNext()) { logger.error("Missing required options: " + missingOptionsIterator.next() + "\n"); } usage(); System.exit(1); } catch (MissingArgumentException a) { logger.error("Missing required argument for option: " + a.getOption().getOpt() + "/" + a.getOption().getLongOpt() + "<" + a.getOption().getArgName() + ">"); usage(); System.exit(2); } catch (ParseException e) { logger.error("Error parsing command line arguments, exiting..."); logger.error(e.getMessage(), e); System.exit(3); } catch (IOException e) { logger.error("Error creating output path at " + outputPath.toAbsolutePath().toString()); logger.error(e.getMessage(), e); logger.error("Exiting..."); System.exit(4); } }
From source file:net.bican.wordpress.configuration.CliConfiguration.java
/** * // w ww .j ava 2 s . co m * generates the configuration in terms of arguments and options * * @param args Command line arguments * @param options Command line options * @throws ParseException When the configuration cannot be parsed */ public CliConfiguration(String[] args, Options options) throws ParseException { CommandLineParser parser = new BasicParser(); CommandLine commandLine = parser.parse(options, args); for (Option option : commandLine.getOptions()) { String key = option.getLongOpt(); String val = option.getValue(); if (val == null) { this.addProperty(key, "N/A"); } else { this.addProperty(key, val); } } }
From source file:com.teradata.tempto.runner.TemptoRunnerOptions.java
public boolean isSet(Option option) { return getValue(option.getLongOpt()).map(v -> v.equals(TRUE.toString())).orElse(false); }
From source file:de.hsos.ecs.richwps.wpsmonitor.boundary.cli.command.CommandFormatter.java
private String optList(final Option opt) { final String lOptName = opt.getLongOpt(); final StringBuilder strBuilder = new StringBuilder(); strBuilder.append(decorateOptionName(opt.getOpt())); if (lOptName != null) { strBuilder.append(", ").append(decorateOptionName(opt.getLongOpt())); }/*from w w w. ja v a2 s.com*/ return strBuilder.toString(); }
From source file:de.nrw.hbz.regal.sync.MyConfiguration.java
/** * // www . j a v a 2 s . c o m * generates the configuration in terms of arguments and options * * @param args * Command line arguments * @param options * Command line options * @throws ParseException * When the configuration cannot be parsed */ MyConfiguration(String[] args, Options options) { try { CommandLineParser parser = new BasicParser(); CommandLine commandLine = parser.parse(options, args); for (Option option : commandLine.getOptions()) { String key = option.getLongOpt(); // System.out.println(key); if (key.compareTo("set") == 0) { String[] vals = option.getValues(); if (vals == null || vals.length == 0) { this.addProperty(key, "N/A"); } else { StringBuffer val = new StringBuffer(); for (int i = 0; i < vals.length; i++) { val.append(vals[i]); val.append(","); } val.delete(val.length(), val.length()); this.addProperty(key, val.toString()); } } else { String val = option.getValue(); if (val == null) { this.addProperty(key, "N/A"); } else { this.addProperty(key, val); } } } } catch (ParseException e) { throw new ConfigurationParseException(e); } }
From source file:com.marklogic.contentpump.utilities.CommandlineOption.java
public CommandlineOption(Option opt) throws IllegalArgumentException { super(opt.getOpt(), opt.hasArg(), opt.getDescription()); this.setLongOpt(opt.getLongOpt()); this.setRequired(opt.isRequired()); this.setArgName(opt.getArgName()); this.setArgs(opt.getArgs()); this.setOptionalArg(opt.hasOptionalArg()); this.setType(opt.getType()); this.setValueSeparator(opt.getValueSeparator()); }
From source file:com.cloudera.csd.tools.codahale.AbstractCodahaleFixtureGenerator.java
public AbstractCodahaleFixtureGenerator(String[] args, Options options) throws Exception { Preconditions.checkNotNull(args);/*from www .j a va2 s . c o m*/ Preconditions.checkNotNull(options); CommandLineParser parser = new DefaultParser(); try { CommandLine cmdLine = parser.parse(options, args); if (!cmdLine.getArgList().isEmpty()) { throw new ParseException("Unexpected extra arguments: " + cmdLine.getArgList()); } config = new MapConfiguration(Maps.<String, Object>newHashMap()); for (Option option : cmdLine.getOptions()) { config.addProperty(option.getLongOpt(), option.getValue()); } } catch (ParseException ex) { IOUtils.write("Error: " + ex.getMessage() + "\n", System.err); printUsageMessage(System.err, options); throw ex; } }
From source file:com.comcast.cats.vision.CATSVisionApplication.java
/** * Pull out the command line arguments prior to loading the form. Properties * are being used so that they can be written out to disk. * //from w ww. j a v a 2s. com * @param args */ @Override protected void initialize(String[] args) { Options options = new Options(); options.addOption("s", "server", true, "CATS server URL"); options.addOption("m", "mac", true, "MAC id of Settop"); String arg; CommandLineParser parser = new PosixParser(); try { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Command Line Arguments", options); CommandLine cmd = parser.parse(options, args); for (Option opt : cmd.getOptions()) { switch (opt.getLongOpt()) { case "server": arg = opt.getValue(); System.setProperty(CatsProperties.SERVER_URL_PROPERTY, arg); break; case "mac": arg = opt.getValue(); System.setProperty(CatsProperties.SETTOP_DEFAULT_PROPERTY, arg); break; default: arg = opt.getValue(); } } } catch (ParseException e) { logger.error("Command line argument parsing error"); e.printStackTrace(); } // Time to grab our ApplicationContext. setupApplicationContext(); /* * Now that we have CATS_HOME established, let's setup our logging for * CATS Vision. */ LogConfiguration logConfiguration = new LogConfiguration(); logConfiguration.configureLogging(); logger = Logger.getLogger(CATSVisionApplication.class); }
From source file:de.weltraumschaf.groundzero.opt.commons.OptionComparator.java
/** * Finds the order position of a option configuration. * * The method throws a {@link IllegalArgumentException}, if the position can not be determined * of a given option.// ww w.ja v a 2 s. c om * * @param option must not be {@code null} * @return non negative integer */ int findPositionForKey(final Option option) { final String shortOption = option.getOpt(); final String longOption = option.getLongOpt(); for (OptionDescriptor desc : ORDER) { if (desc.getShortOption().equals(shortOption) || desc.getLongOption().equals(longOption)) { return ORDER.indexOf(desc); } } throw new IllegalArgumentException(String.format("Unconfigured option: %s!", option)); }