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
  • Field Details

  • Constructor Details

  • Method Details

    • getComparator

      Gets the comparator for sorting options.
      Returns:
      The comparator for sorting options.
    • getHelpAppendable

      Gets the help appendable.
      Returns:
      The help appendable.
    • 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

      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 Options 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 a collection of 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 final void printHelp(String cmdLineSyntax, String header, Options 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 Options 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
      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

      Return the string representation of the options as used in the syntax display.
      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

      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

      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.