# Class AbstractHelpFormatter

java.lang.Object
org.apache.commons.cli.help.AbstractHelpFormatter

Direct Known Subclasses:
  `HelpFormatter`

public abstract class AbstractHelpFormatter extends Object
Helps formatters provides the framework to link a `HelpAppendable` with a `OptionFormatter` and a default `TableDefinition` so to produce standardized format help output.

Since:
  1.10.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `AbstractHelpFormatter.Builder<B extends AbstractHelpFormatter.Builder<B,T>, T extends AbstractHelpFormatter>`
  Abstracts building instances for subclasses.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final Comparator<Option>`
  `DEFAULT_COMPARATOR`
  The default comparator for `Option` implementations.
  `static final String`
  `DEFAULT_OPTION_GROUP_SEPARATOR`
  The default separator between `OptionGroup` elements: " | ".
  `static final String`
  `DEFAULT_SYNTAX_PREFIX`
  The string to display at the beginning of the usage statement: "usage: ".

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `AbstractHelpFormatter(AbstractHelpFormatter.Builder<?,?> builder)`
  Constructs the base formatter.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Comparator<Option>`
  `getComparator()`
  Gets the comparator for sorting options.
  `protected HelpAppendable`
  `getHelpAppendable()`
  Gets the help appendable.
  `protected OptionFormatter.Builder`
  `getOptionFormatBuilder()`
  Gets the option formatter builder.
  `final OptionFormatter`
  `getOptionFormatter(Option option)`
  Constructs an `OptionFormatter` for the specified `Option`.
  `protected String`
  `getOptionGroupSeparator()`
  Gets the option group separator.
  `final HelpAppendable`
  `getSerializer()`
  Gets the `HelpAppendable` associated with this help formatter.
  `final String`
  `getSyntaxPrefix()`
  Gets the currently set syntax prefix.
  `protected abstract TableDefinition`
  `getTableDefinition(Iterable<Option> options)`
  Converts a collection of `Option`s into a `TableDefinition`.
  `void`
  `printHelp(String cmdLineSyntax, String header, Iterable<Option> options, String footer, boolean autoUsage)`
  Prints the help for `Options` with the specified command line syntax.
  `void`
  `printHelp(String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage)`
  Prints the help for a collection of `Option`s with the specified command line syntax.
  `final void`
  `printOptions(Iterable<Option> options)`
  Prints the option table for a collection of `Option` objects to the `HelpAppendable`.
  `final void`
  `printOptions(TableDefinition tableDefinition)`
  Prints a `TableDefinition` to the `HelpAppendable`.
  `final void`
  `printOptions(Options options)`
  Prints the option table for the specified `Options` to the `HelpAppendable`.
  `final void`
  `setSyntaxPrefix(String prefix)`
  Sets the syntax prefix.
  `List<Option>`
  `sort(Iterable<Option> options)`
  Creates a new list of options ordered by the comparator.
  `List<Option>`
  `sort(Options options)`
  Creates a new list of options ordered by the comparator.
  `final String`
  `toArgName(String argName)`
  Formats the `argName` as an argument a defined in the enclosed `OptionFormatter.Builder`.
  `String`
  `toSyntaxOptions(Iterable<Option> options)`
  Return the string representation of the options as used in the syntax display.
  `protected String`
  `toSyntaxOptions(Iterable<Option> options, Function<Option, OptionGroup> lookup)`
  Return the string representation of the options as used in the syntax display.
  `String`
  `toSyntaxOptions(OptionGroup group)`
  Return the string representation of the options as used in the syntax display.
  `String`
  `toSyntaxOptions(Options options)`
  Return the string representation of the options as used in the syntax display.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### DEFAULT_COMPARATOR

    public static final Comparator<Option> DEFAULT_COMPARATOR
    The default comparator for `Option` implementations.

  - ### DEFAULT_OPTION_GROUP_SEPARATOR

    public static final String DEFAULT_OPTION_GROUP_SEPARATOR
    The default separator between `OptionGroup` elements: " | ".
    See Also:
      - Constant Field Values

  - ### DEFAULT_SYNTAX_PREFIX

    public static final String DEFAULT_SYNTAX_PREFIX
    The string to display at the beginning of the usage statement: "usage: ".
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### AbstractHelpFormatter

    protected AbstractHelpFormatter(AbstractHelpFormatter.Builder<?,?> builder)
    Constructs the base formatter.
    Parameters:
      `builder` - the builder.

- ## Method Details

  - ### getComparator

    protected Comparator<Option> getComparator()
    Gets the comparator for sorting options.
    Returns:
      The comparator for sorting options.

  - ### getHelpAppendable

    protected HelpAppendable getHelpAppendable()
    Gets the help appendable.
    Returns:
      The help appendable.

  - ### getOptionFormatBuilder

    protected OptionFormatter.Builder getOptionFormatBuilder()
    Gets the option formatter builder.
    Returns:
      The option formatter builder.

  - ### getOptionFormatter

    public final OptionFormatter getOptionFormatter(Option option)
    Constructs an `OptionFormatter` for the specified `Option`.
    Parameters:
      `option` - The Option to format.
    Returns:
      an `OptionFormatter` for the specified `Option`.

  - ### getOptionGroupSeparator

    protected String getOptionGroupSeparator()
    Gets the option group separator.
    Returns:
      The option group separator.

  - ### getSerializer

    public final HelpAppendable getSerializer()
    Gets the `HelpAppendable` associated with this help formatter.
    Returns:
      The `HelpAppendable` associated with this help formatter.

  - ### getSyntaxPrefix

    public final String getSyntaxPrefix()
    Gets the currently set syntax prefix.
    Returns:
      The currently set syntax prefix.

  - ### getTableDefinition

    protected abstract TableDefinition getTableDefinition(Iterable<Option> options)
    Converts a collection of `Option`s into a `TableDefinition`.
    Parameters:
      `options` - The options to create a table for.
    Returns:
      the TableDefinition.

  - ### printHelp

    public void printHelp(String cmdLineSyntax, String header, Iterable<Option> options, String footer, boolean autoUsage) throws IOException
    Prints the help for `Options` with the specified command line syntax.
    Parameters:
      `cmdLineSyntax` - the syntax for this application.
      `header` - the banner to display at the beginning of the help.
      `options` - the collection of `Option` objects to print.
      `footer` - the banner to display at the end of the help.
      `autoUsage` - whether to print an automatically generated usage statement.
    Throws:
      `IOException` - If the output could not be written to the `HelpAppendable`.

  - ### printHelp

    public void printHelp(String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage) throws IOException
    Prints the help for a collection of `Option`s with the specified command line syntax.
    Parameters:
      `cmdLineSyntax` - the syntax for this application.
      `header` - the banner to display at the beginning of the help.
      `options` - the collection of `Option` objects to print.
      `footer` - the banner to display at the end of the help.
      `autoUsage` - whether to print an automatically generated usage statement.
    Throws:
      `IOException` - If the output could not be written to the `HelpAppendable`.

  - ### printOptions

    public final void printOptions(Iterable<Option> options) throws IOException
    Prints the option table for a collection of `Option` objects to the `HelpAppendable`.
    Parameters:
      `options` - the collection of Option objects to print in the table.
    Throws:
      `IOException` - If the output could not be written to the `HelpAppendable`.

  - ### printOptions

    public final void printOptions(Options options) throws IOException
    Prints the option table for the specified `Options` to the `HelpAppendable`.
    Parameters:
      `options` - the Options to print in the table.
    Throws:
      `IOException` - If the output could not be written to the `HelpAppendable`.

  - ### printOptions

    public final void printOptions(TableDefinition tableDefinition) throws IOException
    Prints a `TableDefinition` to the `HelpAppendable`.
    Parameters:
      `tableDefinition` - the `TableDefinition` to print.
    Throws:
      `IOException` - If the output could not be written to the `HelpAppendable`.

  - ### setSyntaxPrefix

    public final void setSyntaxPrefix(String prefix)
    Sets the syntax prefix. This is the phrase that is printed before the syntax line.
    Parameters:
      `prefix` - the new value for the syntax prefix.

  - ### sort

    public List<Option> sort(Iterable<Option> options)
    Creates a new list of options ordered by the comparator.
    Parameters:
      `options` - the Options to sort.
    Returns:
      a new list of options ordered by the comparator.

  - ### sort

    public List<Option> sort(Options options)
    Creates a new list of options ordered by the comparator.
    Parameters:
      `options` - the Options to sort.
    Returns:
      a new list of options ordered by the comparator.

  - ### toArgName

    public final String toArgName(String argName)
    Formats the `argName` as an argument a defined in the enclosed `OptionFormatter.Builder`.
    Parameters:
      `argName` - the string to format as an argument.
    Returns:
      the `argName` formatted as an argument.

  - ### toSyntaxOptions

    public String toSyntaxOptions(Iterable<Option> options)
    Return the string representation of the options as used in the syntax display.

    This is probably not the method you want. This method does not track the presence of option groups. To display the option grouping use `toSyntaxOptions(Options)` or `toSyntaxOptions(OptionGroup)` for individual groups.

    Parameters:
      `options` - The collection of `Option` instances to create the string representation for.
    Returns:
      the string representation of the options as used in the syntax display.

  - ### toSyntaxOptions

    protected String toSyntaxOptions(Iterable<Option> options, Function<Option, OptionGroup> lookup)
    Return the string representation of the options as used in the syntax display.
    Parameters:
      `options` - The options to create the string representation for.
      `lookup` - a function to determine if the Option is part of an OptionGroup that has already been processed.
    Returns:
      the string representation of the options as used in the syntax display.

  - ### toSyntaxOptions

    public String toSyntaxOptions(OptionGroup group)
    Return the string representation of the options as used in the syntax display.
    Parameters:
      `group` - The OptionGroup to create the string representation for.
    Returns:
      the string representation of the options as used in the syntax display.

  - ### toSyntaxOptions

    public String toSyntaxOptions(Options options)
    Return the string representation of the options as used in the syntax display.
    Parameters:
      `options` - The `Options` to create the string representation for.
    Returns:
      the string representation of the options as used in the syntax display.