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

    • DEFAULT_WIDTH

      public static final int DEFAULT_WIDTH
      Default number of characters per line: 74.
      See Also:
    • DEFAULT_LEFT_PAD

      public static final int DEFAULT_LEFT_PAD
      Default padding to the left of each line: 1.
      See Also:
    • DEFAULT_COLUMN_SPACING

      public static final int DEFAULT_COLUMN_SPACING
      The default number of spaces between columns in the options table: 5.
      See Also:
    • showSince

      private final boolean showSince
      If true show the "Since" column, otherwise ignore it.
  • Constructor Details

    • HelpFormatter

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