spring-framework / org.springframework.core.env / JOptCommandLinePropertySource

JOptCommandLinePropertySource

open class JOptCommandLinePropertySource : CommandLinePropertySource<OptionSet>

CommandLinePropertySource implementation backed by a JOpt OptionSet. Typical usage Configure and execute an OptionParser against the String[] of arguments supplied to the main method, and create a JOptCommandLinePropertySource using the resulting OptionSet object:

 public static void main(String[] args) { OptionParser parser = new OptionParser(); parser.accepts("option1"); parser.accepts("option2").withRequiredArg(); OptionSet options = parser.parse(args); PropertySource ps = new JOptCommandLinePropertySource(options); // ... }
See CommandLinePropertySource for complete general usage examples.

Requires JOpt Simple version 4.3 or higher. Tested against JOpt up until 5.0.

Author
Chris Beams

Author
Juergen Hoeller

Author
Dave Syer

Since
3.1

See Also
CommandLinePropertySourcejoptsimple.OptionParserjoptsimple.OptionSet

Constructors

<init>

JOptCommandLinePropertySource(options: OptionSet)

Create a new JOptCommandLinePropertySource having the default name and backed by the given OptionSet.

JOptCommandLinePropertySource(name: String, options: OptionSet)

Create a new JOptCommandLinePropertySource having the given name and backed by the given OptionSet.

Inherited Properties

COMMAND_LINE_PROPERTY_SOURCE_NAME

static val COMMAND_LINE_PROPERTY_SOURCE_NAME: String

The default name given to CommandLinePropertySource instances: {@value}

DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME

static val DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME: String

The default name of the property representing non-option arguments: {@value}

Functions

getOptionValues

open fun getOptionValues(name: String): MutableList<String>

getPropertyNames

open fun getPropertyNames(): Array<String>

Inherited Functions

containsProperty

fun containsProperty(name: String): Boolean

This implementation first checks to see if the name specified is the special "non-option arguments" property, and if so delegates to the abstract #getNonOptionArgs() method checking to see whether it returns an empty collection. Otherwise delegates to and returns the value of the abstract #containsOption(String) method.

getProperty

fun getProperty(name: String): String

This implementation first checks to see if the name specified is the special "non-option arguments" property, and if so delegates to the abstract #getNonOptionArgs() method. If so and the collection of non-option arguments is empty, this method returns null. If not empty, it returns a comma-separated String of all non-option arguments. Otherwise delegates to and returns the result of the abstract method.

setNonOptionArgsPropertyName

open fun setNonOptionArgsPropertyName(nonOptionArgsPropertyName: String): Unit

Specify the name of the special "non-option arguments" property. The default is {@value #DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME}.