List of usage examples for org.apache.commons.cli Option getOpt
public String getOpt()
From source file:net.mitnet.tools.pdf.book.common.cli.CommandLineHelper.java
/** * Returns the Option value as a File.//from w ww.j av a 2s. c o m */ public File getOptionValueAsFile(Option option) { return getOptionValueAsFile(option.getOpt()); }
From source file:com.github.riccardove.easyjasub.commandline.CommandLineOptionList.java
public void printHelp(PrintWriter stream, String usage, String header, String footer) { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { @Override//w w w .jav a 2s . co m public int compare(Option opt1, Option opt2) { return (int) Math.signum(optionsOrder.get(opt1.getOpt()) - optionsOrder.get(opt2.getOpt())); } }); formatter.printHelp(stream, HelpFormatter.DEFAULT_WIDTH, usage, header, options, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, footer); }
From source file:net.mitnet.tools.pdf.book.common.cli.CommandLineHelper.java
/** * Returns true if an option has been set. *//*from ww w .j a va2s.c om*/ public boolean hasOption(Option option) { return commandLine.hasOption(option.getOpt()); }
From source file:net.mitnet.tools.pdf.book.common.cli.CommandLineHelper.java
/** * Returns the Option value as an Integer. *///from w w w .jav a 2 s . c o m public Integer getOptionValueAsInteger(Option option) { return getOptionValueAsInteger(option.getOpt()); }
From source file:net.mitnet.tools.pdf.book.common.cli.CommandLineHelper.java
/** * Returns the Option value./*from w w w . j a v a2 s .c o m*/ */ public String getOptionValue(Option option) { return commandLine.getOptionValue(option.getOpt()); }
From source file:com.kylinolap.job.tools.OptionsHelper.java
public String getOptionsAsString() { StringBuilder buf = new StringBuilder(); for (Option option : commandLine.getOptions()) { buf.append(" "); buf.append(option.getOpt()); if (option.hasArg()) { buf.append("="); buf.append(option.getValue()); }// w w w .j av a 2 s.c om } return buf.toString(); }
From source file:com.dal.a.ui.DalAppConsole.java
public void config(CommandLine cli) { for (Option opt : cli.getOptions()) { config.addProperty(opt.getOpt(), opt.getValues()); }/*from w w w. jav a 2 s.c o m*/ }
From source file:com.conversantmedia.mapreduce.tool.PosixParserRequiredProps.java
@Override protected void processProperties(Properties properties) { super.processProperties(properties); if (properties == null) { return;// ww w.ja v a 2s . com } for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) { String option = e.nextElement().toString(); if (cmd.hasOption(option)) { Option opt = getOptions().getOption(option); this.getRequiredOptions().remove(opt.getOpt()); } } }
From source file:com.googlecode.jmxtrans.cli.CommonsCliArgumentParser.java
/** Parse the options given on the command line. */ @Nonnull/*from w w w. j a v a 2s . c o m*/ @Override public JmxTransConfiguration parseOptions(@Nonnull String[] args) throws OptionsException, org.apache.commons.cli.ParseException { CommandLineParser parser = new GnuParser(); CommandLine cl = parser.parse(getOptions(), args); Option[] options = cl.getOptions(); JmxTransConfiguration configuration = new JmxTransConfiguration(); for (Option option : options) { if (option.getOpt().equals("c")) { configuration.setContinueOnJsonError(Boolean.parseBoolean(option.getValue())); } else if (option.getOpt().equals("j")) { File jsonDir = new File(option.getValue()); if (jsonDir.exists() && jsonDir.isDirectory()) { configuration.setJsonDir(jsonDir); } else { throw new OptionsException("Path to json directory is invalid: " + jsonDir); } } else if (option.getOpt().equals("f")) { File jsonFile = new File(option.getValue()); if (jsonFile.exists() && jsonFile.isFile()) { configuration.setJsonFile(jsonFile); } else { throw new OptionsException("Path to json file is invalid: " + jsonFile); } } else if (option.getOpt().equals("e")) { configuration.setRunEndlessly(true); } else if (option.getOpt().equals("q")) { File quartzConfigFile = new File(option.getValue()); if (quartzConfigFile.exists() && quartzConfigFile.isFile()) { configuration.setQuartzPropertiesFile(quartzConfigFile); } else { throw new OptionsException("Could not find path to the quartz properties file: " + quartzConfigFile.getAbsolutePath()); } } else if (option.getOpt().equals("s")) { try { configuration.setRunPeriod(Integer.parseInt(option.getValue())); } catch (NumberFormatException nfe) { throw new OptionsException("Seconds between server job runs must be an integer"); } } else if (option.getOpt().equals("a")) { configuration.setAdditionalJars(option.getValuesList()); } else if (option.getOpt().equals("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar jmxtrans-all.jar", getOptions()); configuration.setHelp(true); } } if ((!configuration.isHelp()) && (configuration.getJsonDirOrFile() == null)) { throw new OptionsException("Please specify either the -f or -j option."); } return configuration; }
From source file:henplus.AbstractCommand.java
@Override public String getLongDescription(final String cmd) { final Collection<Option> handledCommandLineOptions = getHandledCommandLineOptions(); if (handledCommandLineOptions != null && handledCommandLineOptions.size() > 0) { final StringBuilder sb = new StringBuilder("\tRecognized options are:\n"); for (final Option option : handledCommandLineOptions) { sb.append(String.format("\t -%s %s\n", option.getOpt(), option.getDescription())); }/* www.ja va 2s. c o m*/ return sb.toString(); } return null; }