Class EnvironmentVariableDefaultProvider
java.lang.Object
com.beust.jcommander.defaultprovider.EnvironmentVariableDefaultProvider
- All Implemented Interfaces:
IDefaultProvider
A default provider that reads its default values from an environment
variable.
A prefix pattern can be provided to indicate how options are identified.
The default pattern
-/ mandates that options MUST start with either a dash or a slash.
Options can have values separated by whitespace.
Values can contain whitespace as long as they are single-quoted or double-quoted.
Otherwhise whitespace identifies the end of a value.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a default provider reading the environment variableJCOMMANDER_OPTSusing the prefixes pattern-/.EnvironmentVariableDefaultProvider(String environmentVariableName, String optionPrefixes) Creates a default provider reading the specified environment variable using the specified prefixes pattern.EnvironmentVariableDefaultProvider(String environmentVariableName, String optionPrefixes, Function<String, String> resolver) For Unit Tests Only: Allows to mock the resolver, as Java cannot set environment variables. -
Method Summary
-
Field Details
-
DEFAULT_VARIABLE_NAME
- See Also:
-
DEFAULT_PREFIXES_PATTERN
- See Also:
-
environmentVariableValue
-
optionPrefixesPattern
-
-
Constructor Details
-
EnvironmentVariableDefaultProvider
public EnvironmentVariableDefaultProvider()Creates a default provider reading the environment variableJCOMMANDER_OPTSusing the prefixes pattern-/. -
EnvironmentVariableDefaultProvider
Creates a default provider reading the specified environment variable using the specified prefixes pattern.- Parameters:
environmentVariableName- The name of the environment variable to read (e. g."JCOMMANDER_OPTS"). Must not benull.optionPrefixes- A set of characters used to indicate the start of an option (e. g."-/"if option names may start with either dash or slash). Must not benull.
-
EnvironmentVariableDefaultProvider
EnvironmentVariableDefaultProvider(String environmentVariableName, String optionPrefixes, Function<String, String> resolver) For Unit Tests Only: Allows to mock the resolver, as Java cannot set environment variables.- Parameters:
environmentVariableName- The name of the environment variable to read. May benullif the passed resolver doesn't use it (e. g. Unit Test).optionPrefixes- A set of characters used to indicate the start of an option (e. g."-/"if option names may start with either dash or slash). Must not benull.resolver- Reads the value from the environment variable (e. g.System::getenv). Must not benull.
-
-
Method Details
-
getDefaultValueFor
- Specified by:
getDefaultValueForin interfaceIDefaultProvider- Parameters:
optionName- The name of the option as specified in the names() attribute of the @Parameter option (e.g. "-file").- Returns:
- the default value for this option.
-