public class JCommander extends Object
Modifier and Type | Class and Description |
---|---|
static class |
JCommander.Builder |
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)
Deprecated.
Construct a JCommander instance first and then call parse() on it.
|
Modifier and Type | Method and Description |
---|---|
void |
addCommand(Object object) |
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)
Adds a factory to lookup string converters.
|
void |
addConverterInstanceFactory(IStringConverterInstanceFactory converterInstanceFactory)
Adds a factory to lookup string converters.
|
void |
addObject(Object object)
Adds the provided arg object to the set of objects that this commander
will parse arguments into.
|
Object |
convertValue(Parameterized parameterized,
Class type,
String optionName,
String value) |
int |
getColumnSize() |
String |
getCommandDescription(String commandName) |
Map<String,JCommander> |
getCommands() |
static com.beust.jcommander.internal.Console |
getConsole() |
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() |
String |
getProgramName()
Get the program name (used only in the usage).
|
List<String> |
getUnknownOptions() |
boolean |
isParameterOverwritingAllowed() |
static JCommander.Builder |
newBuilder() |
void |
parse(String... args)
Parse and validate the command line parameters.
|
void |
parseWithoutValidation(String... args)
Parse the command line parameters without validating them.
|
void |
setAcceptUnknownOptions(boolean b) |
void |
setAllowAbbreviatedOptions(boolean b) |
void |
setAllowParameterOverwriting(boolean b) |
void |
setAtFileCharset(Charset charset)
Sets the charset used to expand
@files . |
void |
setCaseSensitiveOptions(boolean b) |
void |
setColumnSize(int columnSize) |
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 |
setExpandAtSign(boolean expandAtSign)
Disables expanding
@file . |
void |
setParameterDescriptionComparator(Comparator<? super ParameterDescription> c) |
void |
setProgramName(String name)
Set the program name (used only in the usage).
|
void |
setProgramName(String name,
String... aliases)
Set the program name
|
void |
setVerbose(int verbose) |
void |
usage()
Display 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).@Deprecated public JCommander(Object object, String... args)
object
- The arg object expected to contain Parameter
annotations.args
- The arguments to parse (optional).public void setExpandAtSign(boolean expandAtSign)
@file
.
JCommander supports the @file
syntax, which allows you to put all your options
into a file and pass this file as parameter @param expandAtSign whether to expand @file
.public static com.beust.jcommander.internal.Console getConsole()
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 String getProgramName()
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 static JCommander.Builder newBuilder()
public void usage(StringBuilder out)
public void usage(StringBuilder out, String indent)
public void setParameterDescriptionComparator(Comparator<? super ParameterDescription> c)
public void setColumnSize(int columnSize)
public int getColumnSize()
public List<ParameterDescription> getParameters()
public ParameterDescription getMainParameter()
public void setDefaultProvider(IDefaultProvider defaultProvider)
public void addConverterFactory(IStringConverterFactory converterFactory)
converterFactory
- the factory determining string converterspublic void addConverterInstanceFactory(IStringConverterInstanceFactory converterInstanceFactory)
converterInstanceFactory
- the factory generating string converter instancespublic Object convertValue(Parameterized parameterized, Class type, String optionName, String value)
type
- The type of the actual parameteroptionName
- value
- The value to convertpublic void addCommand(Object object)
public 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
.public List<Object> getObjects()
public void setVerbose(int verbose)
public void setCaseSensitiveOptions(boolean b)
public void setAllowAbbreviatedOptions(boolean b)
public void setAcceptUnknownOptions(boolean b)
public void setAllowParameterOverwriting(boolean b)
public boolean isParameterOverwritingAllowed()
public void setAtFileCharset(Charset charset)
@files
.charset
- the charsetCopyright © 2017. All rights reserved.