List of usage examples for org.apache.commons.cli Options getOptionGroup
public OptionGroup getOptionGroup(Option opt)
opt
belongs to. From source file:com.somerledsolutions.pa11y.client.cli.OptionsBuilderTest.java
@Test public void testBuildPa11yOptions() throws Exception { Options options = OptionsBuilder.buildPa11yOptions(); assertEquals(10, options.getOptions().size()); assertPa11yOptions(options);//w ww .j av a2 s . c om OptionGroup optionGroup = options.getOptionGroup(options.getOption("c")); Collection<String> optionGroupNames = optionGroup.getNames(); assertTrue(optionGroupNames.contains("c")); assertTrue(optionGroupNames.contains("l")); assertTrue(optionGroupNames.contains("r")); assertTrue(optionGroupNames.contains("g")); assertTrue(optionGroupNames.contains("d")); }
From source file:com.zimbra.cs.util.SoapCLI.java
/** * Returns an <tt>Options</tt> object that combines the standard options * and the hidden ones./*from w w w . ja v a2s . c o m*/ */ @SuppressWarnings("unchecked") private Options getAllOptions() { Options newOptions = new Options(); Set<OptionGroup> groups = new HashSet<OptionGroup>(); Options[] optionses = new Options[] { mOptions, mHiddenOptions }; for (Options options : optionses) { for (Option opt : (Collection<Option>) options.getOptions()) { OptionGroup group = options.getOptionGroup(opt); if (group != null) { groups.add(group); } else { newOptions.addOption(opt); } } } for (OptionGroup group : groups) { newOptions.addOptionGroup(group); } return newOptions; }
From source file:org.apache.accumulo.core.util.shell.commands.SetScanIterCommand.java
@Override public Options getOptions() { // Remove the options that specify which type of iterator this is, since // they are all scan iterators with this command. final HashSet<OptionGroup> groups = new HashSet<OptionGroup>(); final Options parentOptions = super.getOptions(); final Options modifiedOptions = new Options(); for (Iterator<?> it = parentOptions.getOptions().iterator(); it.hasNext();) { Option o = (Option) it.next(); if (!IteratorScope.majc.name().equals(o.getOpt()) && !IteratorScope.minc.name().equals(o.getOpt()) && !IteratorScope.scan.name().equals(o.getOpt())) { modifiedOptions.addOption(o); OptionGroup group = parentOptions.getOptionGroup(o); if (group != null) groups.add(group);/*from www . j a va 2 s . c om*/ } } for (OptionGroup group : groups) { modifiedOptions.addOptionGroup(group); } return modifiedOptions; }
From source file:org.apache.accumulo.core.util.shell.commands.SetShellIterCommand.java
@Override public Options getOptions() { // Remove the options that specify which type of iterator this is, since // they are all scan iterators with this command. final HashSet<OptionGroup> groups = new HashSet<OptionGroup>(); final Options parentOptions = super.getOptions(); final Options modifiedOptions = new Options(); for (Iterator<?> it = parentOptions.getOptions().iterator(); it.hasNext();) { Option o = (Option) it.next(); if (!IteratorScope.majc.name().equals(o.getOpt()) && !IteratorScope.minc.name().equals(o.getOpt()) && !IteratorScope.scan.name().equals(o.getOpt()) && !"table".equals(o.getLongOpt())) { modifiedOptions.addOption(o); OptionGroup group = parentOptions.getOptionGroup(o); if (group != null) groups.add(group);//w w w . j a va2 s. com } } for (OptionGroup group : groups) { modifiedOptions.addOptionGroup(group); } profileOpt = new Option("pn", "profile", true, "iterator profile name"); profileOpt.setRequired(true); profileOpt.setArgName("profile"); modifiedOptions.addOption(profileOpt); return modifiedOptions; }
From source file:org.apache.geronimo.cli.PrintHelper.java
public void printUsage(PrintWriter pw, int width, String app, Options options) { // create a list for processed option groups ArrayList list = new ArrayList(); StringBuilder optionsBuff = new StringBuilder(); // temp variable Option option;//w w w . ja v a 2 s . co m // iterate over the options for (Iterator i = options.getOptions().iterator(); i.hasNext();) { // get the next Option option = (Option) i.next(); // check if the option is part of an OptionGroup OptionGroup group = options.getOptionGroup(option); // if the option is part of a group and the group has not already // been processed if (group != null && !list.contains(group)) { // add the group to the processed list list.add(group); // get the names of the options from the OptionGroup Collection names = group.getNames(); optionsBuff.append("["); // for each option in the OptionGroup for (Iterator iter = names.iterator(); iter.hasNext();) { optionsBuff.append(iter.next()); if (iter.hasNext()) { optionsBuff.append("|"); } } optionsBuff.append("] "); } else if (group == null) { // if the Option is not part of an OptionGroup // if the Option is not a required option if (!option.isRequired()) { optionsBuff.append("["); } if (!" ".equals(option.getOpt())) { optionsBuff.append("-").append(option.getOpt()); } else { optionsBuff.append("--").append(option.getLongOpt()); } if (option.hasArg()) { optionsBuff.append(" "); } // if the Option has a value if (option.hasArg()) { optionsBuff.append(option.getArgName()); } // if the Option is not a required option if (!option.isRequired()) { optionsBuff.append("]"); } optionsBuff.append(" "); } } app = app.replace("$options", optionsBuff.toString()); // call printWrapped printWrapped(pw, width, app.indexOf(' ') + 1, app); }