Package com.beust.jcommander
Class DefaultUsageFormatter
java.lang.Object
com.beust.jcommander.DefaultUsageFormatter
- All Implemented Interfaces:
IUsageFormatter
- Direct Known Subclasses:
UnixStyleUsageFormatter
The default usage formatter.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
appendAllParametersDetails
(StringBuilder out, int indentCount, String indent, List<ParameterDescription> sortedParameters) Appends the details of all parameters in the given order to the argument string builder, indenting every line with indentCount-many indent.void
appendCommands
(StringBuilder out, int indentCount, int descriptionIndent, String indent) Appends the details of all commands to the argument string builder, indenting every line with indentCount-many indent.void
appendMainLine
(StringBuilder out, boolean hasOptions, boolean hasCommands, int indentCount, String indent) Appends the main line segment of the usage to the argument string builder, indenting every line with indentCount-many indent.getCommandDescription
(String commandName) Returns the description of the command corresponding to the argument command name.static String
getI18nString
(ResourceBundle bundle, String key, String def) Returns the internationalized version of the string if available, otherwise it returns def.static String
s
(int count) Returns count-many spaces.final void
Prints the usage toJCommander.getConsole()
on the underlying commander instance.final void
usage
(StringBuilder out) Store the usage in the argument string builder.void
usage
(StringBuilder out, String indent) Stores the usage in the argument string builder, with the argument indentation.final void
usage
(String commandName, StringBuilder out) Store the usage for the argument command in the argument string builder.final void
usage
(String commandName, StringBuilder out, String indent) Store the usage for the command in the argument string builder, indenting every line with the value of indent.void
wrapDescription
(StringBuilder out, int indent, int currentLineIndent, String description) Wrap a potentially long line to the value obtained by callingJCommander.getColumnSize()
on the underlying commander instance.void
wrapDescription
(StringBuilder out, int indent, String description) Wrap a potentially long line to { @link #commander#getColumnSize()}.
-
Constructor Details
-
DefaultUsageFormatter
-
-
Method Details
-
usage
Prints the usage toJCommander.getConsole()
on the underlying commander instance.- Specified by:
usage
in interfaceIUsageFormatter
-
usage
Store the usage for the argument command in the argument string builder.- Specified by:
usage
in interfaceIUsageFormatter
-
usage
Store the usage in the argument string builder.- Specified by:
usage
in interfaceIUsageFormatter
-
usage
Store the usage for the command in the argument string builder, indenting every line with the value of indent.- Specified by:
usage
in interfaceIUsageFormatter
-
usage
Stores the usage in the argument string builder, with the argument indentation. This works by appending each portion of the help in the following order. Their outputs can be modified by overriding them in a subclass of this class.- Specified by:
usage
in interfaceIUsageFormatter
-
appendMainLine
public void appendMainLine(StringBuilder out, boolean hasOptions, boolean hasCommands, int indentCount, String indent) Appends the main line segment of the usage to the argument string builder, indenting every line with indentCount-many indent.- Parameters:
out
- the builder to append tohasOptions
- if the options section should be appendedhasCommands
- if the comments section should be appendedindentCount
- the amount of indentation to applyindent
- the indentation
-
appendAllParametersDetails
public void appendAllParametersDetails(StringBuilder out, int indentCount, String indent, List<ParameterDescription> sortedParameters) Appends the details of all parameters in the given order to the argument string builder, indenting every line with indentCount-many indent.- Parameters:
out
- the builder to append toindentCount
- the amount of indentation to applyindent
- the indentationsortedParameters
- the parameters to append to the builder
-
appendCommands
public void appendCommands(StringBuilder out, int indentCount, int descriptionIndent, String indent) Appends the details of all commands to the argument string builder, indenting every line with indentCount-many indent. The commands are obtained from callingJCommander.getRawCommands()
and the commands are resolved usingJCommander.findCommandByAlias(String)
on the underlying commander instance.- Parameters:
out
- the builder to append toindentCount
- the amount of indentation to applydescriptionIndent
- the indentation for the descriptionindent
- the indentation
-
getCommandDescription
Returns the description of the command corresponding to the argument command name. The commands are resolved by callingJCommander.findCommandByAlias(String)
, and the default resource bundle used fromJCommander.getBundle()
on the underlying commander instance.- Specified by:
getCommandDescription
in interfaceIUsageFormatter
- Parameters:
commandName
- the name of the command to get the description for- Returns:
- the description of the command.
-
wrapDescription
public void wrapDescription(StringBuilder out, int indent, int currentLineIndent, String description) Wrap a potentially long line to the value obtained by callingJCommander.getColumnSize()
on the underlying commander instance.- Parameters:
out
- the outputindent
- the indentation in spaces for lines after the first line.currentLineIndent
- the length of the indentation of the initial linedescription
- the text to wrap. No extra spaces are inserted beforedescription
. If the first line needs to be indented prepend the correct number of spaces todescription
.
-
wrapDescription
Wrap a potentially long line to { @link #commander#getColumnSize()}.- Parameters:
out
- the outputindent
- the indentation in spaces for lines after the first line.description
- the text to wrap. No extra spaces are inserted beforedescription
. If the first line needs to be indented prepend the correct number of spaces todescription
.- See Also:
-
getI18nString
Returns the internationalized version of the string if available, otherwise it returns def.- Returns:
- the internationalized version of the string if available, otherwise it returns def
-
s
Returns count-many spaces.- Returns:
- count-many spaces
-