List of usage examples for org.apache.commons.cli Option getOpt
public String getOpt()
From source file:com.github.dmyersturnbull.transformations.CommandLineHelper.java
@Nonnull public CommandLineHelper addOptions(@Nonnull Option... additionalOptions) { for (Option option : additionalOptions) { m_options.addOption(option);/*ww w. j a va 2 s.co m*/ if (m_shortNames.contains(option.getOpt())) { throw new IllegalArgumentException("Option with short name " + option.getOpt() + " already exists"); } m_shortNames.add(option.getOpt()); if (option.getLongOpt() != null) { if (m_longNames.contains(option.getLongOpt())) { throw new IllegalArgumentException( "Option with long name " + option.getLongOpt() + " already exists"); } m_longNames.add(option.getLongOpt()); } } return this; }
From source file:com.bbva.kltt.apirest.core.launcher.GlobalLauncher.java
/** * Return the String option value from the command line given the representing option * * @param option with the representing option of the command line * @return the value of the option, null if unsettled */// ww w . j av a 2s. c om protected String getCmdStringOption(final Option option) { if (this.commandLine.hasOption(option.getOpt())) { return this.commandLine.getOptionValue(option.getOpt()).trim(); } else if (this.commandLine.hasOption(option.getLongOpt())) { return this.commandLine.getOptionValue(option.getLongOpt()).trim(); } return null; }
From source file:com.github.horrorho.liquiddonkey.settings.commandline.CommandLineOptions.java
public String opt(Option option) { return option.hasLongOpt() ? option.getLongOpt() : option.getOpt(); }
From source file:com.cloudera.cli.validator.components.CommandLineOptions.java
public String getOptionValue(Option option) { Preconditions.checkNotNull(option); return cmdLine.getOptionValue(option.getOpt()); }
From source file:de.clusteval.serverclient.MyOptionComparator.java
@Override public int compare(Object o1, Object o2) { Option opt1 = (Option) o1; Option opt2 = (Option) o2; if (opt1.isRequired() && !opt2.isRequired()) return -1; else if (!opt1.isRequired() && opt2.isRequired()) return 1; return opt1.getOpt().compareToIgnoreCase(opt2.getOpt()); }
From source file:gobblin.runtime.cli.PublicMethodsGobblinCliFactory.java
private Options inferOptionsFromMethods() { Options options = new Options(); for (Method method : klazz.getMethods()) { if (canUseMethod(method)) { EmbeddedGobblinCliOption annotation = method.isAnnotationPresent(EmbeddedGobblinCliOption.class) ? method.getAnnotation(EmbeddedGobblinCliOption.class) : null;/*from w w w . j ava 2 s. c o m*/ String optionName = annotation == null || Strings.isNullOrEmpty(annotation.name()) ? method.getName() : annotation.name(); String description = annotation == null ? "" : annotation.description(); Option.Builder builder = Option.builder(optionName).desc(description); boolean hasArg = method.getParameterTypes().length > 0; if (hasArg) { builder.hasArg(); } Option option = builder.build(); options.addOption(option); this.methodsMap.put(option.getOpt(), method); } } return options; }
From source file:com.googlecode.dex2jar.tools.BaseCmd.java
public void doMain(String... args) { initOptions();/*from www. j a v a 2s . c om*/ CommandLineParser parser = new PosixParser(); try { commandLine = parser.parse(options, args); } catch (ParseException ex) { usage(); return; } this.remainingArgs = commandLine.getArgs(); try { for (Option option : commandLine.getOptions()) { String opt = option.getOpt(); Field f = map.get(opt); if (f != null) { Object value; if (!option.hasArg()) {// no arg, it's a flag option value = true; } else { value = convert(commandLine.getOptionValue(opt), f.getType()); } f.set(this, value); } } doCommandLine(); } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:com.bc.fiduceo.ingest.IngestionToolTest.java
@Test public void testGetOptions() { final Options options = IngestionTool.getOptions(); assertNotNull(options);/*from w w w .ja v a 2 s . c o m*/ final Option helpOption = options.getOption("h"); assertNotNull(helpOption); assertEquals("h", helpOption.getOpt()); assertEquals("help", helpOption.getLongOpt()); assertEquals("Prints the tool usage.", helpOption.getDescription()); assertFalse(helpOption.hasArg()); final Option sensorOption = options.getOption("sensor"); assertNotNull(sensorOption); assertEquals("s", sensorOption.getOpt()); assertEquals("sensor", sensorOption.getLongOpt()); assertEquals("Defines the sensor to be ingested.", sensorOption.getDescription()); assertTrue(sensorOption.hasArg()); final Option configOption = options.getOption("config"); assertNotNull(configOption); assertEquals("c", configOption.getOpt()); assertEquals("config", configOption.getLongOpt()); assertEquals("Defines the configuration directory. Defaults to './config'.", configOption.getDescription()); assertTrue(configOption.hasArg()); final Option startTime = options.getOption("start-time"); assertNotNull(startTime); assertEquals("start", startTime.getOpt()); assertEquals("start-time", startTime.getLongOpt()); assertEquals("Define the starting time of products to inject.", startTime.getDescription()); assertTrue(startTime.hasArg()); final Option endTime = options.getOption("end-time"); assertNotNull(endTime); assertEquals("end", endTime.getOpt()); assertEquals("end-time", endTime.getLongOpt()); assertEquals("Define the ending time of products to inject.", endTime.getDescription()); assertTrue(endTime.hasArg()); final Option version = options.getOption("version"); assertNotNull(version); assertEquals("v", version.getOpt()); assertEquals("version", version.getLongOpt()); assertEquals("Define the sensor version.", version.getDescription()); assertTrue(version.hasArg()); }
From source file:com.kaikoda.cah.CardGeneratorOptions.java
/** * Prints an annotated list of the options that are valid for use with this * application./*from ww w . j a v a 2 s.co m*/ * * @return a list of all the Card Generator options. */ private String getHelp() { String help = "The options that can be used with this application are:\n"; Collection<Option> optionsCollection = this.getOptions(); Iterator<Option> validOptions = optionsCollection.iterator(); while (validOptions.hasNext()) { Option option = validOptions.next(); help = help + "\n-" + option.getOpt() + "\t" + option.getDescription() + "\n"; } return help; }
From source file:edu.vt.middleware.ldap.AbstractCli.java
/** * Initialize the supplied config with command line options. * * @param config property config to configure * @param line Parsed command line arguments container. * * @throws Exception On errors thrown by handler. *///from ww w . j a v a 2s . c o m protected void initLdapProperties(final PropertyConfig config, final CommandLine line) throws Exception { final LdapProperties ldapProperties = new LdapProperties(config); for (Option o : line.getOptions()) { if (o.getOpt().equals(OPT_USE_PROPERTIES)) { ldapProperties.useDefaultPropertiesFile(); } else if (!this.opts.contains(o.getOpt())) { ldapProperties.setProperty(o.getOpt(), o.getValue()); } } ldapProperties.configure(); }