Class 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 Detail

      • 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
      • showSince

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

      • HelpFormatter

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