public class ArgumentParser extends Object
| Modifier and Type | Field and Description |
|---|---|
protected String |
applicationName |
protected org.apache.commons.cli.CommandLine |
commandLine |
protected org.apache.commons.cli.Options |
options |
protected org.apache.commons.cli.Options |
optionsIgnoreRequired |
| Constructor and Description |
|---|
ArgumentParser(String applicationName) |
| Modifier and Type | Method and Description |
|---|---|
org.apache.commons.cli.Option |
addArgument(org.apache.commons.cli.Option option,
boolean required)
Adds an option instance.
|
org.apache.commons.cli.Option |
addArgument(String opt,
String longOpt,
boolean hasArg,
String description,
boolean required)
Creates and adds an Option using the specified parameters.
|
String |
getApplicationName()
Returns the application name that this instance of ArgumentParser was created for.
|
Boolean |
getBooleanValue(org.apache.commons.cli.Option option)
Query to see if an option has been set.
|
Collection |
getConfiguredOptions()
Retrieve a read-only list of options in this set
|
File |
getFileValue(org.apache.commons.cli.Option option)
Retrieves the argument as a File object, if any, of an option.
|
File |
getFileValue(org.apache.commons.cli.Option option,
File defaultValue)
Retrieves the argument as a File object, if any, of an option.
|
Integer |
getIntegerValue(org.apache.commons.cli.Option option)
Retrieves the argument as an Integer object, if any, of an option.
|
Integer |
getIntegerValue(org.apache.commons.cli.Option option,
Integer defaultValue)
Retrieves the argument as an Integer object, if any, of an option.
|
Integer |
getIntegerValue(org.apache.commons.cli.Option option,
Integer defaultValue,
Integer minValue,
Integer maxValue)
Retrieves the argument as an Integer object, if any, of an option and validates it against minimum and maximum allowed values.
|
String |
getStringValue(org.apache.commons.cli.Option option)
Retrieves the argument as a String object, if any, of an option.
|
String |
getStringValue(org.apache.commons.cli.Option option,
String defaultValue)
Retrieves the argument as a String object, if any, of an option.
|
Boolean |
getStringValueAsBoolean(org.apache.commons.cli.Option option,
Boolean defaultValue)
Retrieves the argument value, if any, as a String object and converts it to a boolean value.
|
String |
getUsageInformation()
Returns a help message, including the program usage and information about the arguments registered with the ArgumentParser.
|
void |
parseArguments(String[] args)
Parses the arguments according to the specified options.
|
void |
parseArguments(String[] args,
boolean failOnMissingRequiredOptions)
Parses the arguments according to the specified options and properties.
|
protected String applicationName
protected org.apache.commons.cli.Options options
protected org.apache.commons.cli.Options optionsIgnoreRequired
protected org.apache.commons.cli.CommandLine commandLine
public ArgumentParser(String applicationName)
applicationName - The application name.public String getApplicationName()
public org.apache.commons.cli.Option addArgument(org.apache.commons.cli.Option option,
boolean required)
option - the option that is to be addedrequired - specifies whether the option being added is mandatorypublic org.apache.commons.cli.Option addArgument(String opt, String longOpt, boolean hasArg, String description, boolean required)
opt - Short single-character name of the option.longOpt - Long multi-character name of the option.hasArg - flag signally if an argument is required after this optiondescription - Self-documenting descriptionrequired - specifies whether the option being added is mandatorypublic Collection getConfiguredOptions()
Option objects in this descriptorpublic void parseArguments(String[] args, boolean failOnMissingRequiredOptions) throws org.apache.commons.cli.ParseException
args - the command line arguments passed to the programfailOnMissingRequiredOptions - specifies whether to fail on any missing mandatory optionsorg.apache.commons.cli.ParseExceptionpublic void parseArguments(String[] args) throws org.apache.commons.cli.ParseException
args - the command line arguments passed to the programorg.apache.commons.cli.ParseExceptionpublic String getUsageInformation()
public Boolean getBooleanValue(org.apache.commons.cli.Option option) throws IllegalStateException
option - the option that we want to query forIllegalStateExceptionpublic Boolean getStringValueAsBoolean(org.apache.commons.cli.Option option, Boolean defaultValue) throws org.apache.commons.cli.ParseException
option - the option that we want to query fordefaultValue - the default value to return if option is not set or missing an argument valueorg.apache.commons.cli.ParseException - if the value of the argument is an invalid boolean valuepublic String getStringValue(org.apache.commons.cli.Option option) throws IllegalStateException
option - the option that we want argument value to be returned forIllegalStateExceptionpublic String getStringValue(org.apache.commons.cli.Option option, String defaultValue)
option - the option that we want argument value to be returned fordefaultValue - is the default value to be returned if the option is not specifiedpublic Integer getIntegerValue(org.apache.commons.cli.Option option) throws NumberFormatException
option - the option that we want argument value to be returned forNumberFormatException - if there are problems parsing the option value into the Integer typepublic Integer getIntegerValue(org.apache.commons.cli.Option option, Integer defaultValue) throws NumberFormatException
option - the option that we want argument value to be returned fordefaultValue - is the default value to be returned if the option is not specifiedNumberFormatException - if there are problems parsing the option value into the Integer typepublic Integer getIntegerValue(org.apache.commons.cli.Option option, Integer defaultValue, Integer minValue, Integer maxValue) throws IllegalArgumentException
option - the option that we want argument value to be returned fordefaultValue - is the default value to be returned if the option is not specifiedminValue - the minimum allowed Integer value for the optionmaxValue - the maximum allowed Integer value for the optionIllegalArgumentException - if there are problems with the option valuepublic File getFileValue(org.apache.commons.cli.Option option)
option - the option that we want argument value to be returned forpublic File getFileValue(org.apache.commons.cli.Option option, File defaultValue)
option - the option that we want argument value to be returned fordefaultValue - is the default value to be returned if the option is not specifiedCopyright © 2021. All rights reserved.