Package org.apache.commons.cli.help
Class HelpFormatter
java.lang.Object
org.apache.commons.cli.help.AbstractHelpFormatter
org.apache.commons.cli.help.HelpFormatter
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 ClassesModifier and TypeClassDescriptionstatic class
A builder for the HelpFormatter. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The default number of spaces between columns in the options table: 5.static final int
Default padding to the left of each line: 1.static final int
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
ConstructorsModifierConstructorDescriptionprotected
HelpFormatter
(HelpFormatter.Builder builder) Constructs the Help formatter. -
Method Summary
Modifier and TypeMethodDescriptionstatic HelpFormatter.Builder
builder()
Constructs a new builder.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
-
Field Details
-
DEFAULT_WIDTH
Default number of characters per line: 74.- See Also:
-
DEFAULT_LEFT_PAD
Default padding to the left of each line: 1.- See Also:
-
DEFAULT_COLUMN_SPACING
The default number of spaces between columns in the options table: 5.- See Also:
-
-
Constructor Details
-
HelpFormatter
Constructs the Help formatter.- Parameters:
builder
- the Builder to build from.
-
-
Method Details
-
builder
Constructs a new builder.- Returns:
- a new builder.
-
getTableDefinition
Gets the table definition for the options.- Specified by:
getTableDefinition
in classAbstractHelpFormatter
- Parameters:
options
- the collection ofOption
instances to create the table from.- Returns:
- A
TableDefinition
to display the options.
-