public abstract class AbstractHelpFormatter extends Object
HelpAppendable with a OptionFormatter and a default TableDefinition so to produce
standardized format help output.| Modifier and Type | Class | Description |
|---|---|---|
static class |
AbstractHelpFormatter.Builder<B extends AbstractHelpFormatter.Builder<B,T>,T extends AbstractHelpFormatter> |
Abstracts building instances for subclasses.
|
| Modifier and Type | Field | Description |
|---|---|---|
static Comparator<Option> |
DEFAULT_COMPARATOR |
The default comparator for
Option implementations. |
static String |
DEFAULT_OPTION_GROUP_SEPARATOR |
The default separator between
OptionGroup elements: " | ". |
static String |
DEFAULT_SYNTAX_PREFIX |
The string to display at the beginning of the usage statement: "usage: ".
|
| Modifier | Constructor | Description |
|---|---|---|
protected |
AbstractHelpFormatter(AbstractHelpFormatter.Builder<?,?> builder) |
Constructs the base formatter.
|
| Modifier and Type | Method | Description |
|---|---|---|
protected Comparator<Option> |
getComparator() |
Gets the comparator for sorting options.
|
protected HelpAppendable |
getHelpAppendable() |
Gets the help appendable.
|
protected OptionFormatter.Builder |
getOptionFormatBuilder() |
Gets the option formatter builder.
|
OptionFormatter |
getOptionFormatter(Option option) |
Constructs an
OptionFormatter for the specified Option. |
protected String |
getOptionGroupSeparator() |
Gets the option group separator.
|
HelpAppendable |
getSerializer() |
Gets the
HelpAppendable associated with this help formatter. |
String |
getSyntaxPrefix() |
Gets the currently set syntax prefix.
|
protected abstract TableDefinition |
getTableDefinition(Iterable<Option> options) |
Converts a collection of
Options into a TableDefinition. |
void |
printHelp(String cmdLineSyntax,
String header,
Iterable<Option> options,
String footer,
boolean autoUsage) |
Prints the help for
Options with the specified command line syntax. |
void |
printHelp(String cmdLineSyntax,
String header,
Options options,
String footer,
boolean autoUsage) |
Prints the help for a collection of
Options with the specified command line syntax. |
void |
printOptions(Iterable<Option> options) |
Prints the option table for a collection of
Option objects to the HelpAppendable. |
void |
printOptions(Options options) |
Prints the option table for the specified
Options to the HelpAppendable. |
void |
printOptions(TableDefinition tableDefinition) |
Prints a
TableDefinition to the HelpAppendable. |
void |
setSyntaxPrefix(String prefix) |
Sets the syntax prefix.
|
List<Option> |
sort(Iterable<Option> options) |
Creates a new list of options ordered by the comparator.
|
List<Option> |
sort(Options options) |
Creates a new list of options ordered by the comparator.
|
String |
toArgName(String argName) |
Formats the
argName as an argument a defined in the enclosed OptionFormatter.Builder. |
String |
toSyntaxOptions(Iterable<Option> options) |
Return the string representation of the options as used in the syntax display.
|
protected String |
toSyntaxOptions(Iterable<Option> options,
Function<Option,OptionGroup> lookup) |
Return the string representation of the options as used in the syntax display.
|
String |
toSyntaxOptions(OptionGroup group) |
Return the string representation of the options as used in the syntax display.
|
String |
toSyntaxOptions(Options options) |
Return the string representation of the options as used in the syntax display.
|
public static final Comparator<Option> DEFAULT_COMPARATOR
Option implementations.public static final String DEFAULT_OPTION_GROUP_SEPARATOR
OptionGroup elements: " | ".public static final String DEFAULT_SYNTAX_PREFIX
protected AbstractHelpFormatter(AbstractHelpFormatter.Builder<?,?> builder)
builder - the builder.protected Comparator<Option> getComparator()
protected HelpAppendable getHelpAppendable()
protected OptionFormatter.Builder getOptionFormatBuilder()
public final OptionFormatter getOptionFormatter(Option option)
OptionFormatter for the specified Option.option - The Option to format.OptionFormatter for the specified Option.protected String getOptionGroupSeparator()
public final HelpAppendable getSerializer()
HelpAppendable associated with this help formatter.HelpAppendable associated with this help formatter.public final String getSyntaxPrefix()
protected abstract TableDefinition getTableDefinition(Iterable<Option> options)
Options into a TableDefinition.options - The options to create a table for.public void printHelp(String cmdLineSyntax, String header, Iterable<Option> options, String footer, boolean autoUsage) throws IOException
Options with the specified command line syntax.cmdLineSyntax - the syntax for this application.header - the banner to display at the beginning of the help.options - the collection of Option objects to print.footer - the banner to display at the end of the help.autoUsage - whether to print an automatically generated usage statement.IOException - If the output could not be written to the HelpAppendable.public void printHelp(String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage) throws IOException
Options with the specified command line syntax.cmdLineSyntax - the syntax for this application.header - the banner to display at the beginning of the help.options - the collection of Option objects to print.footer - the banner to display at the end of the help.autoUsage - whether to print an automatically generated usage statement.IOException - If the output could not be written to the HelpAppendable.public final void printOptions(Iterable<Option> options) throws IOException
Option objects to the HelpAppendable.options - the collection of Option objects to print in the table.IOException - If the output could not be written to the HelpAppendable.public final void printOptions(Options options) throws IOException
Options to the HelpAppendable.options - the Options to print in the table.IOException - If the output could not be written to the HelpAppendable.public final void printOptions(TableDefinition tableDefinition) throws IOException
TableDefinition to the HelpAppendable.tableDefinition - the TableDefinition to print.IOException - If the output could not be written to the HelpAppendable.public final void setSyntaxPrefix(String prefix)
prefix - the new value for the syntax prefix.public List<Option> sort(Iterable<Option> options)
options - the Options to sort.public List<Option> sort(Options options)
options - the Options to sort.public final String toArgName(String argName)
argName as an argument a defined in the enclosed OptionFormatter.Builder.argName - the string to format as an argument.argName formatted as an argument.public String toSyntaxOptions(Iterable<Option> options)
This is probably not the method you want. This method does not track the presence
of option groups. To display the option grouping use toSyntaxOptions(Options) or
toSyntaxOptions(OptionGroup) for individual groups.
options - The collection of Option instances to create the string representation for.protected String toSyntaxOptions(Iterable<Option> options, Function<Option,OptionGroup> lookup)
options - The options to create the string representation for.lookup - a function to determine if the Option is part of an OptionGroup that has already been processed.public String toSyntaxOptions(OptionGroup group)
group - The OptionGroup to create the string representation for.public String toSyntaxOptions(Options options)
options - The Options to create the string representation for.Copyright © 2002-2025 The Apache Software Foundation. All rights reserved.Apache Commons CLI | Issue management | Source repository