Package org.apache.commons.cli.help
Class AbstractHelpFormatter
java.lang.Object
org.apache.commons.cli.help.AbstractHelpFormatter
- Direct Known Subclasses:
HelpFormatter
Helps formatters provides the framework to link a
HelpAppendable
with a OptionFormatter
and a default TableDefinition
so to produce
standardized format help output.- Since:
- 1.10.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
AbstractHelpFormatter.Builder<B extends AbstractHelpFormatter.Builder<B,
T>, T extends AbstractHelpFormatter> Abstracts building instances for subclasses. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator
<Option> The default comparator forOption
implementations.static final String
The default separator betweenOptionGroup
elements: " | ".static final String
The string to display at the beginning of the usage statement: "usage: ". -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractHelpFormatter
(AbstractHelpFormatter.Builder<?, ?> builder) Constructs the base formatter. -
Method Summary
Modifier and TypeMethodDescriptionprotected Comparator
<Option> Gets the comparator for sorting options.protected HelpAppendable
Gets the help appendable.protected OptionFormatter.Builder
Gets the option formatter builder.final OptionFormatter
getOptionFormatter
(Option option) Constructs anOptionFormatter
for the specifiedOption
.protected String
Gets the option group separator.final HelpAppendable
Gets theHelpAppendable
associated with this help formatter.final String
Gets the currently set syntax prefix.protected abstract TableDefinition
getTableDefinition
(Iterable<Option> options) Converts a collection ofOption
s into aTableDefinition
.void
printHelp
(String cmdLineSyntax, String header, Iterable<Option> options, String footer, boolean autoUsage) Prints the help for a collection ofOption
s with the specified command line syntax.final void
Prints the help forOptions
with the specified command line syntax.final void
printOptions
(Iterable<Option> options) Prints the option table for a collection ofOption
objects to theHelpAppendable
.final void
printOptions
(TableDefinition tableDefinition) Prints aTableDefinition
to theHelpAppendable
.final void
printOptions
(Options options) Prints the option table for the specifiedOptions
to theHelpAppendable
.final void
setSyntaxPrefix
(String prefix) Sets the syntax prefix.Creates a new list of options ordered by the comparator.Creates a new list of options ordered by the comparator.final String
Formats theargName
as an argument a defined in the enclosedOptionFormatter.Builder
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.toSyntaxOptions
(OptionGroup group) Return the string representation of the options as used in the syntax display.toSyntaxOptions
(Options options) Return the string representation of the options as used in the syntax display.
-
Field Details
-
DEFAULT_COMPARATOR
The default comparator forOption
implementations. -
DEFAULT_OPTION_GROUP_SEPARATOR
The default separator betweenOptionGroup
elements: " | ".- See Also:
-
DEFAULT_SYNTAX_PREFIX
The string to display at the beginning of the usage statement: "usage: ".- See Also:
-
-
Constructor Details
-
AbstractHelpFormatter
Constructs the base formatter.- Parameters:
builder
- the builder
-
-
Method Details
-
getComparator
Gets the comparator for sorting options.- Returns:
- The comparator for sorting options.
-
getHelpAppendable
Gets the help appendable.- Returns:
- The help appendable.
-
getOptionFormatBuilder
Gets the option formatter builder.- Returns:
- The option formatter builder.
-
getOptionFormatter
Constructs anOptionFormatter
for the specifiedOption
.- Parameters:
option
- The Option to format.- Returns:
- an
OptionFormatter
for the specifiedOption
.
-
getOptionGroupSeparator
Gets the option group separator.- Returns:
- The option group separator.
-
getSerializer
Gets theHelpAppendable
associated with this help formatter.- Returns:
- The
HelpAppendable
associated with this help formatter.
-
getSyntaxPrefix
Gets the currently set syntax prefix.- Returns:
- The currently set syntax prefix.
-
getTableDefinition
Converts a collection ofOption
s into aTableDefinition
.- Parameters:
options
- The options to create a table for.- Returns:
- the TableDefinition.
-
printHelp
public void printHelp(String cmdLineSyntax, String header, Iterable<Option> options, String footer, boolean autoUsage) throws IOException Prints the help for a collection ofOption
s with the specified command line syntax.- Parameters:
cmdLineSyntax
- the syntax for this applicationheader
- the banner to display at the beginning of the helpoptions
- the collection ofOption
objects to print.footer
- the banner to display at the end of the helpautoUsage
- whether to print an automatically generated usage statement- Throws:
IOException
- If the output could not be written to theHelpAppendable
-
printHelp
public final void printHelp(String cmdLineSyntax, String header, Options options, String footer, boolean autoUsage) throws IOException Prints the help forOptions
with the specified command line syntax.- Parameters:
cmdLineSyntax
- the syntax for this applicationheader
- the banner to display at the beginning of the helpoptions
- theOptions
to printfooter
- the banner to display at the end of the helpautoUsage
- whether to print an automatically generated usage statement- Throws:
IOException
- If the output could not be written to theHelpAppendable
-
printOptions
Prints the option table for a collection ofOption
objects to theHelpAppendable
.- Parameters:
options
- the collection of Option objects to print in the table.- Throws:
IOException
- If the output could not be written to theHelpAppendable
-
printOptions
Prints the option table for the specifiedOptions
to theHelpAppendable
.- Parameters:
options
- the Options to print in the table.- Throws:
IOException
- If the output could not be written to theHelpAppendable
-
printOptions
Prints aTableDefinition
to theHelpAppendable
.- Parameters:
tableDefinition
- theTableDefinition
to print.- Throws:
IOException
- If the output could not be written to theHelpAppendable
-
setSyntaxPrefix
Sets the syntax prefix. This is the phrase that is printed before the syntax line.- Parameters:
prefix
- the new value for the syntax prefix.
-
sort
Creates a new list of options ordered by the comparator.- Parameters:
options
- the Options to sort.- Returns:
- a new list of options ordered by the comparator.
-
sort
Creates a new list of options ordered by the comparator.- Parameters:
options
- the Options to sort.- Returns:
- a new list of options ordered by the comparator.
-
toArgName
Formats theargName
as an argument a defined in the enclosedOptionFormatter.Builder
- Parameters:
argName
- the string to format as an argument.- Returns:
- the
argName
formatted as an argument.
-
toSyntaxOptions
Return the string representation of the options as used in the syntax display.- Parameters:
options
- The collection ofOption
instances to create the string representation for.- Returns:
- the string representation of the options as used in the syntax display.
-
toSyntaxOptions
Return the string representation of the options as used in the syntax display.- Parameters:
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.- Returns:
- the string representation of the options as used in the syntax display.
-
toSyntaxOptions
Return the string representation of the options as used in the syntax display.- Parameters:
group
- The OptionGroup to create the string representation for.- Returns:
- the string representation of the options as used in the syntax display.
-
toSyntaxOptions
Return the string representation of the options as used in the syntax display.- Parameters:
options
- TheOptions
to create the string representation for.- Returns:
- the string representation of the options as used in the syntax display.
-