public class JCommander extends Object
Modifier and Type | Class and Description |
---|---|
static class |
JCommander.Builder |
static class |
JCommander.ProgramName
Encapsulation of either a main application or an individual command.
|
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) |
void |
createDescriptions()
Create the ParameterDescriptions for all the \@Parameter found.
|
JCommander |
findCommandByAlias(String commandOrAlias) |
ResourceBundle |
getBundle() |
int |
getColumnSize() |
Map<String,JCommander> |
getCommands() |
com.beust.jcommander.internal.Console |
getConsole() |
Map<com.beust.jcommander.FuzzyMap.IKey,ParameterDescription> |
getDescriptions() |
Map<Parameterized,ParameterDescription> |
getFields() |
com.beust.jcommander.JCommander.MainParameter |
getMainParameter() |
String |
getMainParameterDescription() |
ParameterDescription |
getMainParameterValue() |
List<Object> |
getObjects() |
com.beust.jcommander.JCommander.Options |
getOptions() |
Comparator<? super ParameterDescription> |
getParameterDescriptionComparator() |
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 |
getProgramDisplayName()
Get the program display name (used only in the usage).
|
String |
getProgramName()
Get the program name (used only in the usage).
|
Map<JCommander.ProgramName,JCommander> |
getRawCommands() |
List<String> |
getUnknownOptions() |
IUsageFormatter |
getUsageFormatter()
Returns the usage formatter.
|
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 |
setConsole(com.beust.jcommander.internal.Console console) |
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 |
setUsageFormatter(IUsageFormatter usageFormatter)
Sets the usage formatter.
|
void |
setVerbose(int verbose) |
void |
usage()
Prints the usage on
getConsole() using the underlying usageFormatter . |
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 void setConsole(com.beust.jcommander.internal.Console console)
public com.beust.jcommander.internal.Console getConsole()
PrintStream
, typically System.out
.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 void createDescriptions()
public String getMainParameterDescription()
public void setProgramName(String name)
public String getProgramName()
public String getProgramDisplayName()
public void setProgramName(String name, String... aliases)
name
- program namealiases
- aliases to the program namepublic void usage()
getConsole()
using the underlying usageFormatter
.public void setUsageFormatter(IUsageFormatter usageFormatter)
usageFormatter
- the usage formatterIllegalArgumentException
- if the argument is nullpublic IUsageFormatter getUsageFormatter()
public com.beust.jcommander.JCommander.Options getOptions()
public Map<com.beust.jcommander.FuzzyMap.IKey,ParameterDescription> getDescriptions()
public com.beust.jcommander.JCommander.MainParameter getMainParameter()
public static JCommander.Builder newBuilder()
public Map<Parameterized,ParameterDescription> getFields()
public Comparator<? super ParameterDescription> getParameterDescriptionComparator()
public void setParameterDescriptionComparator(Comparator<? super ParameterDescription> c)
public void setColumnSize(int columnSize)
public int getColumnSize()
public ResourceBundle getBundle()
public List<ParameterDescription> getParameters()
public ParameterDescription getMainParameterValue()
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 Map<JCommander.ProgramName,JCommander> getRawCommands()
public String getParsedCommand()
public String getParsedAlias()
null
if no
command or alias was specified.null
.public List<Object> getObjects()
public JCommander findCommandByAlias(String commandOrAlias)
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 © 2019. All rights reserved.