Package org.apache.commons.cli.help
Class OptionFormatter
java.lang.Object
org.apache.commons.cli.help.OptionFormatter
The definition of how to display Option attributes.
- Since:
- 1.10.0
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final String[]The delimiters around argument names.A function to display a deprecated option with a "Deprecated" prefix that displays all deprecation information.static final StringThe default argument name: "arg".private static final String[]The default delimiters for an argument namestatic final StringDefault prefix for long options: "--".static final StringThe default separator between the opt and/or longOpt and the argument name: " ".static final StringDefault prefix for short options: "-".static final StringThe default separator between options: ", ".private static final String[]The default delimiters for optional argumentsstatic final StringThe string to display at the beginning of the usage statement: "usage: ".private final StringThe default argument name.The function to display the deprecated option message.private final StringThe prefix for the long option text.A function to display a deprecated option with the "[Deprecated]" prefix.private final Stringthe separator between the opt and/or longOpt and the argument name.private final OptionTheOptionbeing formatted.private final String[]The delimiters for optionalOptions.private final StringThe prefix for the short option text.private final StringThe separator between the options.A function to display a deprecated option with the "[Deprecated]" prefix.private final BiFunction<OptionFormatter, Boolean, String> The method to convert an Option formatter into a syntax notation. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateOptionFormatter(Option option, OptionFormatter.Builder builder) An OptionFormatter applies formatting options to variousOptionattributes for textual display. -
Method Summary
Modifier and TypeMethodDescriptionstatic OptionFormatter.Builderbuilder()Creates a new builder.static OptionFormatterGets the argument name wrapped in the argument name delimiters.Gets both options separated by the specified option separator.Gets the description for the option.Gets the long Opt from the @{link Option} with the associate prefix.getOpt()Gets the Opt from the @{link Option} with the associate prefix.getSince()Gets the "since" value from the Option.booleanGets the required flag from the enclosedOption.toOptional(String text) Wraps the provided text in the optional delimiters.Gets the syntax format for this option.toSyntaxOption(boolean isRequired) Gets the syntax format for this option.
-
Field Details
-
DEFAULT_OPTIONAL_DELIMITERS
The default delimiters for optional arguments -
DEFAULT_ARG_NAME_DELIMITERS
The default delimiters for an argument name -
DEFAULT_ARG_NAME
The default argument name: "arg".- See Also:
-
SIMPLE_DEPRECATED_FORMAT
A function to display a deprecated option with the "[Deprecated]" prefix. -
COMPLEX_DEPRECATED_FORMAT
A function to display a deprecated option with a "Deprecated" prefix that displays all deprecation information. -
NO_DEPRECATED_FORMAT
A function to display a deprecated option with the "[Deprecated]" prefix. -
DEFAULT_SYNTAX_PREFIX
The string to display at the beginning of the usage statement: "usage: ".- See Also:
-
DEFAULT_OPT_PREFIX
Default prefix for short options: "-".- See Also:
-
DEFAULT_LONG_OPT_PREFIX
Default prefix for long options: "--".- See Also:
-
DEFAULT_OPT_SEPARATOR
The default separator between options: ", ".- See Also:
-
DEFAULT_OPT_ARG_SEPARATOR
The default separator between the opt and/or longOpt and the argument name: " ".- See Also:
-
argNameDelimiters
The delimiters around argument names. -
defaultArgName
The default argument name. -
deprecatedFormatFunction
The function to display the deprecated option message. -
longOptPrefix
The prefix for the long option text. -
optPrefix
The prefix for the short option text. -
optSeparator
The separator between the options. -
optArgSeparator
the separator between the opt and/or longOpt and the argument name. -
optionalDelimiters
The delimiters for optionalOptions. -
syntaxFormatFunction
The method to convert an Option formatter into a syntax notation. -
option
TheOptionbeing formatted.
-
-
Constructor Details
-
OptionFormatter
An OptionFormatter applies formatting options to variousOptionattributes for textual display.- Parameters:
option- the Option to apply formatting to.builder- The Builder that specifies the various formatting options.
-
-
Method Details
-
builder
Creates a new builder.- Returns:
- a new builder.
-
from
- Parameters:
option- the option to format.- Returns:
- an OptionFormatter for the specified @{code option}.
-
getArgName
Gets the argument name wrapped in the argument name delimiters.- If option has no arguments an empty string is returned
- If the argument name is not set the default argument name is used.
- Returns:
- The argument name wrapped in the argument name delimiters or an empty string.
-
getBothOpt
Gets both options separated by the specified option separator. Correctly handles the case where one option is not specified.- Returns:
- The one or both of the short and/or long Opt with the associate prefixes.
-
getDescription
Gets the description for the option. This will include any deprecation notices if the deprecated format function has been set.- Returns:
- The Description from the option or an empty string is no description was provided and the option is not deprecated.
-
getLongOpt
Gets the long Opt from the @{link Option} with the associate prefix.- Returns:
- The long Opt from the @{link Option} with the associate prefix or an empty string.
-
getOpt
Gets the Opt from the @{link Option} with the associate prefix.- Returns:
- The Opt from the @{link Option} with the associate prefix or an empty string.
-
getSince
Gets the "since" value from the Option.- Returns:
- The since valeu from the option or "--" if no since value was set.
-
isRequired
public boolean isRequired()Gets the required flag from the enclosedOption.- Returns:
- The required flag from the enclosed
Option.
-
toOptional
Wraps the provided text in the optional delimiters.- Parameters:
text- the text to wrap.- Returns:
- The text wrapped in the optional delimiters or an eppty string of the text is null or an empty string.
-
toSyntaxOption
Gets the syntax format for this option.- Returns:
- the syntax format for this option as specified by the syntaxFormatFunction.
-
toSyntaxOption
Gets the syntax format for this option.- Parameters:
isRequired- iftruethe options is printed as a required option, otherwise it is optional.- Returns:
- the syntax format for this option as specified by the syntaxFormatFunction.
-