@Override public String format(final Map<String, ? extends OptionDescriptor> options) { final Set<OptionDescriptor> opts = new LinkedHashSet<OptionDescriptor>( options.values()); lines.addAll(HELP_PREAMBLE); final int helpIndex = lines.size(); StringBuilder sb; for (final OptionDescriptor descriptor : opts) { if (descriptor.representsNonOptions()) continue; final Collection<String> names = descriptor.options(); sb = new StringBuilder().append(" ") .append(optionsToString(names)); if (descriptor.requiresArgument()) sb.append(" uri"); sb.append(": ").append(descriptor.description()); if (names.contains("help")) lines.add(helpIndex, sb.toString()); else lines.add(sb.toString()); } lines.addAll(HELP_POST); return JOINER.join(lines) + LINE_SEPARATOR; }
/** * Finds the non-option arguments descriptor in the given collection, removes it, and returns it. * * @param options descriptors for the configured options of a parser * @return the non-option arguments descriptor */ protected OptionDescriptor findAndRemoveNonOptionsSpec( Collection<? extends OptionDescriptor> options ) { for ( Iterator<? extends OptionDescriptor> it = options.iterator(); it.hasNext(); ) { OptionDescriptor next = it.next(); if ( next.representsNonOptions() ) { it.remove(); return next; } } throw new AssertionError( "no non-options argument spec" ); }
/** * Finds the non-option arguments descriptor in the given collection, removes it, and returns it. * * @param options descriptors for the configured options of a parser * @return the non-option arguments descriptor */ protected OptionDescriptor findAndRemoveNonOptionsSpec( Collection<? extends OptionDescriptor> options ) { for ( Iterator<? extends OptionDescriptor> it = options.iterator(); it.hasNext(); ) { OptionDescriptor next = it.next(); if ( next.representsNonOptions() ) { it.remove(); return next; } } throw new AssertionError( "no non-options argument spec" ); }
@Override public String format(Map<String, ? extends OptionDescriptor> options) { Comparator<OptionDescriptor> comparator = Comparator.comparing( (optionDescriptor) -> optionDescriptor.options().iterator().next()); Set<OptionDescriptor> sorted = new TreeSet<>(comparator); sorted.addAll(options.values()); for (OptionDescriptor descriptor : sorted) { if (!descriptor.representsNonOptions()) { this.help.add(new OptionHelpAdapter(descriptor)); } } return ""; }
o.append(" "); for (String str : d.options()) { if (!d.representsNonOptions()) { o.append("-");
o.append(" "); for (String str : d.options()) { if (!d.representsNonOptions()) { o.append("-");
/** * <p>Adds help rows for the given options.</p> * * <p>This implementation loops over the given options, and for each, calls {@link #addOptionRow(String, String)} * using the results of {@link #createOptionDisplay(OptionDescriptor)} and * {@link #createDescriptionDisplay(OptionDescriptor)}, respectively, as arguments.</p> * * @param options descriptors for the configured options of a parser */ protected void addOptions( Collection<? extends OptionDescriptor> options ) { for ( OptionDescriptor each : options ) { if ( !each.representsNonOptions() ) addOptionRow( createOptionDisplay( each ), createDescriptionDisplay( each ) ); } }
/** * <p>Adds help rows for the given options.</p> * * <p>This implementation loops over the given options, and for each, calls {@link #addOptionRow(String, String)} * using the results of {@link #createOptionDisplay(OptionDescriptor)} and * {@link #createDescriptionDisplay(OptionDescriptor)}, respectively, as arguments.</p> * * @param options descriptors for the configured options of a parser */ protected void addOptions( Collection<? extends OptionDescriptor> options ) { for ( OptionDescriptor each : options ) { if ( !each.representsNonOptions() ) addOptionRow( createOptionDisplay( each ), createDescriptionDisplay( each ) ); } }
/** * <p>Appends additional info about the given option to the given buffer.</p> * * <p>This implementation:</p> * <ul> * <li>calls {@link #extractTypeIndicator(OptionDescriptor)} for the descriptor</li> * <li>calls {@link joptsimple.OptionDescriptor#argumentDescription()} for the descriptor</li> * <li>if either of the above is present, calls * {@link #appendOptionHelp(StringBuilder, String, String, boolean)}</li> * </ul> * * @param buffer string buffer * @param descriptor a descriptor for a configured option of a parser */ protected void maybeAppendOptionInfo( StringBuilder buffer, OptionDescriptor descriptor ) { String indicator = extractTypeIndicator( descriptor ); String description = descriptor.argumentDescription(); if ( descriptor.acceptsArguments() || !isNullOrEmpty( description ) || descriptor.representsNonOptions() ) { appendOptionHelp( buffer, indicator, description, descriptor.requiresArgument() ); } }
/** * <p>Appends additional info about the given option to the given buffer.</p> * * <p>This implementation:</p> * <ul> * <li>calls {@link #extractTypeIndicator(OptionDescriptor)} for the descriptor</li> * <li>calls {@link joptsimple.OptionDescriptor#argumentDescription()} for the descriptor</li> * <li>if either of the above is present, calls * {@link #appendOptionHelp(StringBuilder, String, String, boolean)}</li> * </ul> * * @param buffer string buffer * @param descriptor a descriptor for a configured option of a parser */ protected void maybeAppendOptionInfo( StringBuilder buffer, OptionDescriptor descriptor ) { String indicator = extractTypeIndicator( descriptor ); String description = descriptor.argumentDescription(); if ( descriptor.acceptsArguments() || !isNullOrEmpty( description ) || descriptor.representsNonOptions() ) { appendOptionHelp( buffer, indicator, description, descriptor.requiresArgument() ); } }