@Override public void addRunOptions(Options baseOptions) { super.addRunOptions(baseOptions); for (Object option : allOptions.getOptions()) { baseOptions.addOption((Option) option); } }
/** * Merges the given {@link Options} into a new Options object. * * @param optionsA options to merge, can be null if none * @param optionsB options to merge, can be null if none * @return */ public static Options mergeOptions(@Nullable Options optionsA, @Nullable Options optionsB) { final Options resultOptions = new Options(); if (optionsA != null) { for (Option option : optionsA.getOptions()) { resultOptions.addOption(option); } } if (optionsB != null) { for (Option option : optionsB.getOptions()) { resultOptions.addOption(option); } } return resultOptions; } }
private static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o); Option jar = OptionBuilder.withArgName("path").hasArg() .withDescription("topology jar of the submitted topology").create("jar"); r.addOption(jar); Option conf = OptionBuilder.withArgName("configuration file").hasArg() .withDescription("an application configuration file").create("conf"); r.addOption(conf); return r; }
private static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o); Option workerNum = OptionBuilder.withArgName("worker num per batch").hasArg() .withDescription("number of workers to upgrade").create("n"); r.addOption(workerNum); Option comp = OptionBuilder.withArgName("component to upgrade").hasArg() .withDescription("component id to upgrade, note that only one component is allowed at a time") .create("p"); r.addOption(comp); Option workers = OptionBuilder.withArgName("workers to upgrade").hasArg() .withDescription("workers to upgrade, in the format: host1:port1,host2:port2,...").create("w"); r.addOption(workers); return r; }
private void addAll(String sectionName, Options adding) { //noinspection unchecked for ( Option o : (Iterable<? extends Option>)adding.getOptions() ) { options.addOption(o); } if ( sectionName != null ) { sections.add(new OptionSection(sectionName, adding)); } } }
static Options buildGeneralOptions(Options opts) { Options r = new Options(); for (Object o : opts.getOptions()) r.addOption((Option) o); Option libjars = OptionBuilder.withArgName("paths").hasArg().withDescription("comma separated jars to be used by the submitted topology").create("libjars"); r.addOption(libjars); optionProcessors.put("libjars", new LibjarsProcessor()); Option conf = OptionBuilder.withArgName("configuration file").hasArg().withDescription("an application configuration file").create("conf"); r.addOption(conf); optionProcessors.put("conf", new ConfFileProcessor()); // Must come after `conf': this option is of higher priority Option extraConfig = OptionBuilder.withArgName("D").hasArg().withDescription("extra configurations (preserving types)").create("D"); r.addOption(extraConfig); optionProcessors.put("D", new ExtraConfigProcessor()); return r; }
for (Object op : normalOptions.getOptions()) { allOptions.addOption((Option)op); for (Object op : DecodeOptions.getOptions()) { allOptions.addOption((Option)op); for (Object op : BuildOptions.getOptions()) { allOptions.addOption((Option)op); for (Object op : frameOptions.getOptions()) { allOptions.addOption((Option)op);
options.addOption(HELP); options.addOption(USE_LOG); for (Option opt : getOptions().getOptions()) { options.addOption(opt);
final List<String> options = command.getOptions().getOptions() .stream().map(o -> "-" + o.getOpt()) .collect(Collectors.toList());
List<Option> optList = new ArrayList<Option>(options.getOptions()); if (getOptionComparator() != null)
@Test public void testOptionComparatorDefaultOrder() throws ParseException { HelpFormatter formatter = new HelpFormatter(); List<Option> options = new ArrayList<Option>(getOptions().getOptions()); Collections.sort(options, formatter.getOptionComparator()); int i = 0; for(Option o: options) { Assert.assertEquals(o.getOpt(), sortOrder.get(i)); i++; } }
private void logOptions(String sectionName, String prefix, Options options) { if ( sectionName != null ) { log.info("== " + sectionName + " =="); } //noinspection unchecked for ( Option option : (Iterable<? extends Option>)options.getOptions() ) { if ( option.hasLongOpt() ) { if ( option.hasArg() ) { log.info(prefix + option.getLongOpt() + " <arg> - " + option.getDescription()); } else { log.info(prefix + option.getLongOpt() + " - " + option.getDescription()); } } } }
@Test public void testOptionComparatorInsertedOrder() throws ParseException { Collection<Option> options = getOptions().getOptions(); int i = 0; for(Option o: options) { Assert.assertEquals(o.getOpt(), insertedOrder.get(i)); i++; } }
@Test public void testEmptyPattern() throws Exception { Options options = PatternOptionBuilder.parsePattern(""); assertTrue(options.getOptions().isEmpty()); }
/** * Prints the info about a command to the given print writer. * * @param command command to print info * @param pw where to print the info */ public static void printCommandInfo(Command command, PrintWriter pw) { String description = String.format("%s: %s", command.getCommandName(), command.getDescription()); int width = 80; try { width = TerminalFactory.get().getWidth(); } catch (Exception e) { // In case the terminal factory failed to decide terminal type, use default width } HELP_FORMATTER.printWrapped(pw, width, description); HELP_FORMATTER.printUsage(pw, width, command.getUsage()); if (command.getOptions().getOptions().size() > 0) { HELP_FORMATTER.printOptions(pw, width, command.getOptions(), HELP_FORMATTER.getLeftPadding(), HELP_FORMATTER.getDescPadding()); } }
); for (Option opt : (Collection<Option>) getSpecificOptions().getOptions()) { options.addOption(opt);
@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<>(); 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); } } for (OptionGroup group : groups) { modifiedOptions.addOptionGroup(group); } return modifiedOptions; }
/** * Retrieve a read-only list of options in this set * * @return read-only Collection of {@link Option} objects in this descriptor */ public Collection getConfiguredOptions() { return options.getOptions(); }
private Options buildOptions(CommandHandler... handlers) { Options opts = new Options(); for (CommandHandler handler : handlers) { Options handlerOpts = handler.getOptions(); handlerOpts.getOptions().iterator() .forEachRemaining(option -> opts.addOption((Option) option)); } return opts; }
private static Options hideOptions(Options originalOptions, String... hiddenOptions) { Options filteredOptions = new Options(); Set<String> hiddenOptionsSet = new HashSet<>(Arrays.asList(hiddenOptions)); originalOptions.getOptions().stream() .filter(o -> !hiddenOptionsSet.contains(o.getLongOpt())) .forEach(filteredOptions::addOption); return filteredOptions; }