Top Description Fields Constructors Methods
com.beust.jcommander.defaultprovider

public final Class EnvironmentVariableDefaultProvider

extends Object
implements IDefaultProvider
Class Inheritance
All Implemented Interfaces
com.beust.jcommander.IDefaultProvider
Imports
com.beust.jcommander.IDefaultProvider, java.util.function.Function, java.util.regex.Matcher, .Pattern

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.
Author
Markus KARG ([email protected])

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private final String
private final String

Constructor Summary

AccessConstructor and Description
public
EnvironmentVariableDefaultProvider()

Creates a default provider reading the environment variable JCOMMANDER_OPTS using the prefixes pattern -/.

public
EnvironmentVariableDefaultProvider(final String
The name of the environment variable to read (e. g. "JCOMMANDER_OPTS"). Must not be null.
environmentVariableName
,
final String
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 be null.
optionPrefixes
)

Creates a default provider reading the specified environment variable using the specified prefixes pattern.

pack-priv
EnvironmentVariableDefaultProvider(final String
The name of the environment variable to read. May be null if the passed resolver doesn't use it (e. g. Unit Test).
environmentVariableName
,
final String
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 be null.
optionPrefixes
,
final Function<String, String>
Reads the value from the environment variable (e. g. System::getenv). Must not be null.
resolver
)

For Unit Tests Only: Allows to mock the resolver, as Java cannot set environment variables.

Method Summary

Modifier and TypeMethod and Description
public final String
getDefaultValueFor(final String
The name of the option as specified in the names() attribute of the @Parameter option (e.g. "-file").
optionName
)

Implements com.beust.jcommander.IDefaultProvider.getDefaultValueFor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_PREFIXES_PATTERNback to summary
private static final String DEFAULT_PREFIXES_PATTERN
DEFAULT_VARIABLE_NAMEback to summary
private static final String DEFAULT_VARIABLE_NAME
environmentVariableValueback to summary
private final String environmentVariableValue
optionPrefixesPatternback to summary
private final String optionPrefixesPattern

Constructor Detail

EnvironmentVariableDefaultProviderback to summary
public EnvironmentVariableDefaultProvider()

Creates a default provider reading the environment variable JCOMMANDER_OPTS using the prefixes pattern -/.

EnvironmentVariableDefaultProviderback to summary
public EnvironmentVariableDefaultProvider(final String environmentVariableName, final String optionPrefixes)

Creates a default provider reading the specified environment variable using the specified prefixes pattern.

Parameters
environmentVariableName:String

The name of the environment variable to read (e. g. "JCOMMANDER_OPTS"). Must not be null.

optionPrefixes:String

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 be null.

EnvironmentVariableDefaultProviderback to summary
pack-priv EnvironmentVariableDefaultProvider(final String environmentVariableName, final String optionPrefixes, final Function<String, String> resolver)

For Unit Tests Only: Allows to mock the resolver, as Java cannot set environment variables.

Parameters
environmentVariableName:String

The name of the environment variable to read. May be null if the passed resolver doesn't use it (e. g. Unit Test).

optionPrefixes:String

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 be null.

resolver:Function<String, String>

Reads the value from the environment variable (e. g. System::getenv). Must not be null.

Method Detail

getDefaultValueForback to summary
public final String getDefaultValueFor(final String optionName)

Implements com.beust.jcommander.IDefaultProvider.getDefaultValueFor.

Parameters
optionName:String

Doc from com.beust.jcommander.IDefaultProvider.getDefaultValueFor.

The name of the option as specified in the names() attribute of the @Parameter option (e.g. "-file").

Returns:String

Doc from com.beust.jcommander.IDefaultProvider.getDefaultValueFor.

the default value for this option.

Annotations
@Override