Package org.apache.commons.cli.help

# Class HelpFormatter

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

public class HelpFormatter extends AbstractHelpFormatter
A default formatter implementation for standard usage.

Example:

     Options options = new Options();
     options.addOption(OptionBuilder.withLongOpt("file").withDescription("The file to be processed").hasArg().withArgName("FILE").isRequired().create('f'));
     options.addOption(OptionBuilder.withLongOpt("version").withDescription("Print the version of the application").create('v'));
     options.addOption(OptionBuilder.withLongOpt("help").create('h'));

     String header = "Do something useful with an input file";
     String footer = "Please report issues at https://example.com/issues";

     HelpFormatter formatter = new HelpFormatter();
     formatter.printHelp("myapp", header, options, footer, true);

This produces the following output:

     usage: myapp -f <FILE> [-h] [-v]
     Do something useful with an input file

      -f,--file <FILE>   The file to be processed
      -h,--help
      -v,--version       Print the version of the application

     Please report issues at https://example.com/issues

Since:
  1.10.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `HelpFormatter.Builder`
  A builder for the HelpFormatter.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `DEFAULT_COLUMN_SPACING`
  The default number of spaces between columns in the options table: 5.
  `static final int`
  `DEFAULT_LEFT_PAD`
  Default padding to the left of each line: 1.
  `static final int`
  `DEFAULT_WIDTH`
  Default number of characters per line: 74.

  ### Fields inherited from class org.apache.commons.cli.help.AbstractHelpFormatter

  `DEFAULT_COMPARATOR, DEFAULT_OPTION_GROUP_SEPARATOR, DEFAULT_SYNTAX_PREFIX`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `HelpFormatter(HelpFormatter.Builder builder)`
  Constructs the Help formatter.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static HelpFormatter.Builder`
  `builder()`
  Constructs a new builder.
  `TableDefinition`
  `getTableDefinition(Iterable<Option> options)`
  Gets the table definition for the options.

  ### Methods inherited from class org.apache.commons.cli.help.AbstractHelpFormatter

  `getComparator, getHelpAppendable, getOptionFormatBuilder, getOptionFormatter, getOptionGroupSeparator, getSerializer, getSyntaxPrefix, printHelp, printHelp, printOptions, printOptions, printOptions, setSyntaxPrefix, sort, sort, toArgName, toSyntaxOptions, toSyntaxOptions, toSyntaxOptions, toSyntaxOptions`

  ### Methods inherited from class java.lang.Object

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

- ## Field Details

  - ### DEFAULT_WIDTH

    public static final int DEFAULT_WIDTH
    Default number of characters per line: 74.
    See Also:
      - Constant Field Values

  - ### DEFAULT_LEFT_PAD

    public static final int DEFAULT_LEFT_PAD
    Default padding to the left of each line: 1.
    See Also:
      - Constant Field Values

  - ### DEFAULT_COLUMN_SPACING

    public static final int DEFAULT_COLUMN_SPACING
    The default number of spaces between columns in the options table: 5.
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### HelpFormatter

    protected HelpFormatter(HelpFormatter.Builder builder)
    Constructs the Help formatter.
    Parameters:
      `builder` - the Builder to build from.

- ## Method Details

  - ### builder

    public static HelpFormatter.Builder builder()
    Constructs a new builder.
    Returns:
      a new builder.

  - ### getTableDefinition

    public TableDefinition getTableDefinition(Iterable<Option> options)
    Gets the table definition for the options.
    Specified by:
      `getTableDefinition` in class `AbstractHelpFormatter`
    Parameters:
      `options` - the collection of `Option` instances to create the table from.
    Returns:
      A `TableDefinition` to display the options.