public class HelpFormatter extends AbstractHelpFormatter
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
| Modifier and Type | Class | Description |
|---|---|---|
static class |
HelpFormatter.Builder |
A builder for the HelpFormatter.
|
| Modifier and Type | Field | Description |
|---|---|---|
static int |
DEFAULT_COLUMN_SPACING |
The default number of spaces between columns in the options table: 5.
|
static int |
DEFAULT_LEFT_PAD |
Default padding to the left of each line: 1.
|
static int |
DEFAULT_WIDTH |
Default number of characters per line: 74.
|
DEFAULT_COMPARATOR, DEFAULT_OPTION_GROUP_SEPARATOR, DEFAULT_SYNTAX_PREFIX| Modifier | Constructor | Description |
|---|---|---|
protected |
HelpFormatter(HelpFormatter.Builder builder) |
Constructs the Help formatter.
|
| 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.
|
getComparator, getHelpAppendable, getOptionFormatBuilder, getOptionFormatter, getOptionGroupSeparator, getSerializer, getSyntaxPrefix, printHelp, printHelp, printOptions, printOptions, printOptions, setSyntaxPrefix, sort, sort, toArgName, toSyntaxOptions, toSyntaxOptions, toSyntaxOptions, toSyntaxOptionspublic static final int DEFAULT_WIDTH
public static final int DEFAULT_LEFT_PAD
public static final int DEFAULT_COLUMN_SPACING
protected HelpFormatter(HelpFormatter.Builder builder)
builder - the Builder to build from.public static HelpFormatter.Builder builder()
public TableDefinition getTableDefinition(Iterable<Option> options)
getTableDefinition in class AbstractHelpFormatteroptions - the collection of Option instances to create the table from.TableDefinition to display the options.Copyright © 2002-2025 The Apache Software Foundation. All rights reserved.Apache Commons CLI | Issue management | Source repository