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