|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.beust.jcommander.JCommander
public class JCommander
The main class for JCommander. It's responsible for parsing the object that contains all the annotated fields, parse the command line and assign the fields with the correct values and a few other helper methods, such as usage(). The object(s) you pass in the constructor are expected to have one or more \@Parameter annotations on them. You can pass either a single object, an array of objects or an instance of Iterable. In the case of an array or Iterable, JCommander will collect the \@Parameter annotations from all the objects passed in parameter.
Field Summary | |
---|---|
static java.lang.String |
DEBUG_PROPERTY
|
Constructor Summary | |
---|---|
JCommander()
Creates a new un-configured JCommander object. |
|
JCommander(java.lang.Object object)
|
|
JCommander(java.lang.Object object,
java.util.ResourceBundle bundle)
|
|
JCommander(java.lang.Object object,
java.util.ResourceBundle bundle,
java.lang.String... args)
|
|
JCommander(java.lang.Object object,
java.lang.String... args)
|
Method Summary | ||
---|---|---|
void |
addCommand(java.lang.Object object)
|
|
void |
addCommand(java.lang.String name,
java.lang.Object object)
Add a command object. |
|
void |
addCommand(java.lang.String name,
java.lang.Object object,
java.lang.String... aliases)
Add a command object and its aliases. |
|
void |
addConverterFactory(IStringConverterFactory converterFactory)
|
|
void |
addObject(java.lang.Object object)
Adds the provided arg object to the set of objects that this commander will parse arguments into. |
|
java.lang.Object |
convertValue(ParameterDescription pd,
java.lang.String value)
|
|
java.lang.Object |
convertValue(Parameterized parameterized,
java.lang.Class type,
java.lang.String value)
|
|
|
findConverter(java.lang.Class<T> cls)
|
|
int |
getColumnSize()
|
|
java.lang.String |
getCommandDescription(java.lang.String commandName)
|
|
java.util.Map<java.lang.String,JCommander> |
getCommands()
|
|
static com.beust.jcommander.internal.Console |
getConsole()
|
|
ParameterDescription |
getMainParameter()
|
|
java.lang.String |
getMainParameterDescription()
|
|
java.util.List<java.lang.Object> |
getObjects()
|
|
java.util.List<ParameterDescription> |
getParameters()
|
|
java.lang.String |
getParsedAlias()
The name of the command or the alias in the form it was passed to the command line. |
|
java.lang.String |
getParsedCommand()
|
|
java.util.List<java.lang.String> |
getUnknownOptions()
|
|
void |
parse(java.lang.String... args)
Parse and validate the command line parameters. |
|
void |
parseWithoutValidation(java.lang.String... args)
Parse the command line parameters without validating them. |
|
void |
setAcceptUnknownOptions(boolean b)
|
|
void |
setAllowAbbreviatedOptions(boolean b)
|
|
void |
setCaseSensitiveOptions(boolean b)
|
|
void |
setColumnSize(int columnSize)
|
|
void |
setDefaultProvider(IDefaultProvider defaultProvider)
Define the default provider for this instance. |
|
void |
setDescriptionsBundle(java.util.ResourceBundle bundle)
Sets the ResourceBundle to use for looking up descriptions. |
|
void |
setParameterDescriptionComparator(java.util.Comparator<? super ParameterDescription> c)
|
|
void |
setProgramName(java.lang.String name)
Set the program name (used only in the usage). |
|
void |
setProgramName(java.lang.String name,
java.lang.String... aliases)
Set the program name |
|
void |
setVerbose(int verbose)
|
|
void |
usage()
Display the help on System.out. |
|
void |
usage(java.lang.String commandName)
Display the usage for this command. |
|
void |
usage(java.lang.StringBuilder out)
Store the help in the passed string builder. |
|
void |
usage(java.lang.StringBuilder out,
java.lang.String indent)
|
|
void |
usage(java.lang.String commandName,
java.lang.StringBuilder out)
Store the help for the command in the passed string builder. |
|
void |
usage(java.lang.String commandName,
java.lang.StringBuilder out,
java.lang.String indent)
Store the help for the command in the passed string builder, indenting every line with "indent". |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEBUG_PROPERTY
Constructor Detail |
---|
public JCommander()
public JCommander(java.lang.Object object)
object
- The arg object expected to contain Parameter
annotations.public JCommander(java.lang.Object object, java.util.ResourceBundle bundle)
object
- The arg object expected to contain Parameter
annotations.bundle
- The bundle to use for the descriptions. Can be null.public JCommander(java.lang.Object object, java.util.ResourceBundle bundle, java.lang.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 JCommander(java.lang.Object object, java.lang.String... args)
object
- The arg object expected to contain Parameter
annotations.args
- The arguments to parse (optional).Method Detail |
---|
public static com.beust.jcommander.internal.Console getConsole()
public final void addObject(java.lang.Object object)
object
- The arg object expected to contain Parameter
annotations. If object
is an array or is Iterable
,
the child objects will be added instead.public final void setDescriptionsBundle(java.util.ResourceBundle bundle)
ResourceBundle
to use for looking up descriptions.
Set this to null
to use description text directly.
public void parse(java.lang.String... args)
public void parseWithoutValidation(java.lang.String... args)
public java.lang.String getMainParameterDescription()
public void setProgramName(java.lang.String name)
public void setProgramName(java.lang.String name, java.lang.String... aliases)
name
- program namealiases
- aliases to the program namepublic void usage(java.lang.String commandName)
public void usage(java.lang.String commandName, java.lang.StringBuilder out)
public void usage(java.lang.String commandName, java.lang.StringBuilder out, java.lang.String indent)
public java.lang.String getCommandDescription(java.lang.String commandName)
public void usage()
public void usage(java.lang.StringBuilder out)
public void usage(java.lang.StringBuilder out, java.lang.String indent)
public void setParameterDescriptionComparator(java.util.Comparator<? super ParameterDescription> c)
public void setColumnSize(int columnSize)
public int getColumnSize()
public java.util.List<ParameterDescription> getParameters()
public ParameterDescription getMainParameter()
public void setDefaultProvider(IDefaultProvider defaultProvider)
public void addConverterFactory(IStringConverterFactory converterFactory)
public <T> java.lang.Class<? extends IStringConverter<T>> findConverter(java.lang.Class<T> cls)
public java.lang.Object convertValue(ParameterDescription pd, java.lang.String value)
public java.lang.Object convertValue(Parameterized parameterized, java.lang.Class type, java.lang.String value)
type
- The type of the actual parametervalue
- The value to convertpublic void addCommand(java.lang.String name, java.lang.Object object)
public void addCommand(java.lang.Object object)
public void addCommand(java.lang.String name, java.lang.Object object, java.lang.String... aliases)
public java.util.Map<java.lang.String,JCommander> getCommands()
public java.lang.String getParsedCommand()
public java.lang.String getParsedAlias()
null
if no
command or alias was specified.
null
.public java.util.List<java.lang.Object> getObjects()
public void setVerbose(int verbose)
public void setCaseSensitiveOptions(boolean b)
public void setAllowAbbreviatedOptions(boolean b)
public void setAcceptUnknownOptions(boolean b)
public java.util.List<java.lang.String> getUnknownOptions()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |