public class JCommander extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEBUG_PROPERTY |
Constructor and Description |
---|
JCommander()
Creates a new un-configured JCommander object.
|
JCommander(Object object) |
JCommander(Object object,
ResourceBundle bundle) |
JCommander(Object object,
ResourceBundle bundle,
String... args) |
JCommander(Object object,
String... args) |
Modifier and Type | Method and Description |
---|---|
void |
addCommand(String name,
Object object)
Add a command object.
|
void |
addCommand(String name,
Object object,
String... aliases)
Add a command object and its aliases.
|
void |
addConverterFactory(IStringConverterFactory converterFactory) |
void |
addObject(Object object)
Adds the provided arg object to the set of objects that this commander
will parse arguments into.
|
Object |
convertValue(Field field,
Class type,
String value) |
Object |
convertValue(ParameterDescription pd,
String value) |
<T> Class<? extends IStringConverter<T>> |
findConverter(Class<T> cls) |
String |
getCommandDescription(String commandName) |
Map<String,JCommander> |
getCommands() |
ParameterDescription |
getMainParameter() |
String |
getMainParameterDescription() |
List<Object> |
getObjects() |
List<ParameterDescription> |
getParameters() |
String |
getParsedAlias()
The name of the command or the alias in the form it was
passed to the command line.
|
String |
getParsedCommand() |
void |
parse(String... args)
Parse and validate the command line parameters.
|
void |
parseWithoutValidation(String... args)
Parse the command line parameters without validating them.
|
void |
setDefaultProvider(IDefaultProvider defaultProvider)
Define the default provider for this instance.
|
void |
setDescriptionsBundle(ResourceBundle bundle)
Sets the
ResourceBundle to use for looking up descriptions. |
void |
setProgramName(String name)
Set the program name (used only in the usage).
|
void |
setProgramName(String name,
String... aliases)
Set the program name
|
void |
usage()
Display a the help on System.out.
|
void |
usage(String commandName)
Display the usage for this command.
|
void |
usage(StringBuilder out)
Store the help in the passed string builder.
|
void |
usage(StringBuilder out,
String indent) |
void |
usage(String commandName,
StringBuilder out)
Store the help for the command in the passed string builder.
|
void |
usage(String commandName,
StringBuilder out,
String indent)
Store the help for the command in the passed string builder, indenting
every line with "indent".
|
public static final String DEBUG_PROPERTY
public JCommander()
public JCommander(Object object)
object
- The arg object expected to contain Parameter
annotations.public JCommander(Object object, ResourceBundle bundle)
object
- The arg object expected to contain Parameter
annotations.bundle
- The bundle to use for the descriptions. Can be null.public JCommander(Object object, ResourceBundle bundle, String... args)
object
- The arg object expected to contain Parameter
annotations.bundle
- The bundle to use for the descriptions. Can be null.args
- The arguments to parse (optional).public final void addObject(Object object)
public final void setDescriptionsBundle(ResourceBundle bundle)
ResourceBundle
to use for looking up descriptions.
Set this to null
to use description text directly.public void parse(String... args)
public void parseWithoutValidation(String... args)
public String getMainParameterDescription()
public void setProgramName(String name)
public void setProgramName(String name, String... aliases)
name
- program namealiases
- aliases to the program namepublic void usage(String commandName)
public void usage(String commandName, StringBuilder out)
public void usage(String commandName, StringBuilder out, String indent)
public String getCommandDescription(String commandName)
public void usage()
public void usage(StringBuilder out)
public void usage(StringBuilder out, String indent)
public List<ParameterDescription> getParameters()
public ParameterDescription getMainParameter()
public void setDefaultProvider(IDefaultProvider defaultProvider)
public void addConverterFactory(IStringConverterFactory converterFactory)
public <T> Class<? extends IStringConverter<T>> findConverter(Class<T> cls)
public Object convertValue(ParameterDescription pd, String value)
public Object convertValue(Field field, Class type, String value)
field
- The fieldtype
- The type of the actual parametervalue
- The value to convertpublic void addCommand(String name, Object object, String... aliases)
public Map<String,JCommander> getCommands()
public String getParsedCommand()
public String getParsedAlias()
null
if no
command or alias was specified.null
.Copyright © 2012. All Rights Reserved.