Top Description Fields Constructors Methods
com.beust.jcommander

public Class DefaultUsageFormatter

extends Object
implements IUsageFormatter
Class Inheritance
All Implemented Interfaces
com.beust.jcommander.IUsageFormatter
Known Direct Subclasses
com.beust.jcommander.UnixStyleUsageFormatter
Imports
com.beust.jcommander.internal.Lists, java.util.*, .ResourceBundle

The default usage formatter.

Field Summary

Modifier and TypeField and Description
private final JCommander

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
appendAllParametersDetails(StringBuilder
the builder to append to
out
,
int
the amount of indentation to apply
indentCount
,
String
the indentation
indent
,
List<ParameterDescription>
the parameters to append to the builder
sortedParameters
)

Appends the details of all parameters in the given order to the argument string builder, indenting every line with indentCount-many indent.

public void
appendCommands(StringBuilder
the builder to append to
out
,
int
the amount of indentation to apply
indentCount
,
int
the indentation for the description
descriptionIndent
,
String
the indentation
indent
)

Appends the details of all commands to the argument string builder, indenting every line with indentCount-many indent.

public void
appendMainLine(StringBuilder
the builder to append to
out
,
boolean
if the options section should be appended
hasOptions
,
boolean
if the comments section should be appended
hasCommands
,
int
the amount of indentation to apply
indentCount
,
String
the indentation
indent
)

Appends the main line segment of the usage to the argument string builder, indenting every line with indentCount-many indent.

public String

Returns:

the description of the command.
getCommandDescription
(String
the name of the command to get the description for
commandName
)

Implements com.beust.jcommander.IUsageFormatter.getCommandDescription.

Returns the description of the command corresponding to the argument command name.
public static String

Returns:

the internationalized version of the string if available, otherwise it returns def
getI18nString
(ResourceBundle bundle, String key, String def)

Returns the internationalized version of the string if available, otherwise it returns def.

private static String

Returns:

new line followed by indent-many spaces
newLineAndIndent
(int indent)

Returns new line followed by indent-many spaces.

public static String

Returns:

count-many spaces
s
(int count)

Returns count-many spaces.

public final void
usage(String commandName)

Implements com.beust.jcommander.IUsageFormatter.usage.

Prints the usage to JCommander#getConsole() on the underlying commander instance.
public final void
usage(String commandName, StringBuilder out)

Implements com.beust.jcommander.IUsageFormatter.usage.

Store the usage for the argument command in the argument string builder.
public final void
usage(StringBuilder out)

Implements com.beust.jcommander.IUsageFormatter.usage.

Store the usage in the argument string builder.
public final void
usage(String commandName, StringBuilder out, String indent)

Implements com.beust.jcommander.IUsageFormatter.usage.

Store the usage for the command in the argument string builder, indenting every line with the value of indent.
public void
usage(StringBuilder out, String indent)

Implements com.beust.jcommander.IUsageFormatter.usage.

Stores the usage in the argument string builder, with the argument indentation.
public void
wrapDescription(StringBuilder
the output
out
,
int
the indentation in spaces for lines after the first line.
indent
,
int
the length of the indentation of the initial line
currentLineIndent
,
String
the text to wrap. No extra spaces are inserted before description. If the first line needs to be indented prepend the correct number of spaces to description.
description
)

Wrap a potentially long line to the value obtained by calling JCommander#getColumnSize() on the underlying commander instance.

public void
wrapDescription(StringBuilder
the output
out
,
int
the indentation in spaces for lines after the first line.
indent
,
String
the text to wrap. No extra spaces are inserted before description. If the first line needs to be indented prepend the correct number of spaces to description.
description
)

Wrap a potentially long line to { @link #commander#getColumnSize()}.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

commanderback to summary
private final JCommander commander

Constructor Detail

DefaultUsageFormatterback to summary
public DefaultUsageFormatter(JCommander commander)

Method Detail

appendAllParametersDetailsback to summary
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:StringBuilder

the builder to append to

indentCount:int

the amount of indentation to apply

indent:String

the indentation

sortedParameters:List<ParameterDescription>

the parameters to append to the builder

appendCommandsback to summary
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 calling JCommander#getRawCommands() and the commands are resolved using JCommander#findCommandByAlias(String) on the underlying commander instance.

Parameters
out:StringBuilder

the builder to append to

indentCount:int

the amount of indentation to apply

descriptionIndent:int

the indentation for the description

indent:String

the indentation

appendMainLineback to summary
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:StringBuilder

the builder to append to

hasOptions:boolean

if the options section should be appended

hasCommands:boolean

if the comments section should be appended

indentCount:int

the amount of indentation to apply

indent:String

the indentation

getCommandDescriptionback to summary
public String getCommandDescription(String commandName)

Implements com.beust.jcommander.IUsageFormatter.getCommandDescription.

Returns the description of the command corresponding to the argument command name. The commands are resolved by calling JCommander#findCommandByAlias(String), and the default resource bundle used from JCommander#getBundle() on the underlying commander instance.

Parameters
commandName:String

the name of the command to get the description for

Returns:String

the description of the command.

getI18nStringback to summary
public static String getI18nString(ResourceBundle bundle, String key, String def)

Returns the internationalized version of the string if available, otherwise it returns def.

Returns:String

the internationalized version of the string if available, otherwise it returns def

newLineAndIndentback to summary
private static String newLineAndIndent(int indent)

Returns new line followed by indent-many spaces.

Returns:String

new line followed by indent-many spaces

sback to summary
public static String s(int count)

Returns count-many spaces.

Returns:String

count-many spaces

usageback to summary
public final void usage(String commandName)

Implements com.beust.jcommander.IUsageFormatter.usage.

Prints the usage to JCommander#getConsole() on the underlying commander instance.

usageback to summary
public final void usage(String commandName, StringBuilder out)

Implements com.beust.jcommander.IUsageFormatter.usage.

Store the usage for the argument command in the argument string builder.

usageback to summary
public final void usage(StringBuilder out)

Implements com.beust.jcommander.IUsageFormatter.usage.

Store the usage in the argument string builder.

usageback to summary
public final void usage(String commandName, StringBuilder out, String indent)

Implements com.beust.jcommander.IUsageFormatter.usage.

Store the usage for the command in the argument string builder, indenting every line with the value of indent.

usageback to summary
public void usage(StringBuilder out, String indent)

Implements com.beust.jcommander.IUsageFormatter.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.

wrapDescriptionback to summary
public void wrapDescription(StringBuilder out, int indent, int currentLineIndent, String description)

Wrap a potentially long line to the value obtained by calling JCommander#getColumnSize() on the underlying commander instance.

Parameters
out:StringBuilder

the output

indent:int

the indentation in spaces for lines after the first line.

currentLineIndent:int

the length of the indentation of the initial line

description:String

the text to wrap. No extra spaces are inserted before description. If the first line needs to be indented prepend the correct number of spaces to description.

wrapDescriptionback to summary
public void wrapDescription(StringBuilder out, int indent, String description)

Wrap a potentially long line to { @link #commander#getColumnSize()}.

Parameters
out:StringBuilder

the output

indent:int

the indentation in spaces for lines after the first line.

description:String

the text to wrap. No extra spaces are inserted before description. If the first line needs to be indented prepend the correct number of spaces to description.

See Also
wrapDescription(StringBuilder, int, int, String)