CommandLinePropertySource implementation backed by a simple String array.
This CommandLinePropertySource implementation aims to provide the simplest
possible approach to parsing command line arguments. As with all CommandLinePropertySource implementations, command line arguments are broken into two
distinct groups: option arguments and non-option arguments, as
described below (some sections copied from Javadoc for
SimpleCommandLineArgsParser):
Option arguments must adhere to the exact syntax:
--optName[=optValue]
That is, options must be prefixed with "--" and may or may not
specify a value. If a value is specified, the name and value must be separated
without spaces by an equals sign ("="). The value may optionally be
an empty string.
--foo --foo= --foo="" --foo=bar --foo="bar then baz" --foo=bar,baz,biz
-foo --foo bar --foo = bar --foo=bar --foo=baz --foo=biz
Any and all arguments specified at the command line without the "--"
option prefix will be considered as "non-option arguments" and made available
through the CommandLineArgs#getNonOptionArgs() method.
public static void main(String[] args) {
PropertySource<?> ps = new SimpleCommandLinePropertySource(args);
// ...
}
See CommandLinePropertySource for complete general usage examples.
When more fully-featured command line parsing is necessary, consider
implementing your own CommandLinePropertySource against the command line
parsing library of your choice.
CommandLinePropertySource
| Access | Constructor and Description |
|---|---|
| public | SimpleCommandLinePropertySource(String... args)
Create a new |
| public | SimpleCommandLinePropertySource(String name, String[] args)
Create a new |
| Modifier and Type | Method and Description |
|---|---|
| protected boolean | containsOption(String name)
Implements abstract org. Return whether the set of option arguments parsed from the command line contains an option with the given name. |
| protected List | getNonOptionArgs()
Implements abstract org. Return the collection of non-option arguments parsed from the command line. |
| protected List | getOptionValues(String name)
Implements abstract org. Return the collection of values associated with the command line option having the given name. |
| public String[] | getPropertyNames()
Implements abstract org. Get the property names for the option arguments. |
| SimpleCommandLinePropertySource | back to summary |
|---|---|
| public SimpleCommandLinePropertySource(String... args) Create a new | |
| SimpleCommandLinePropertySource | back to summary |
|---|---|
| public SimpleCommandLinePropertySource(String name, String[] args) Create a new | |
| containsOption | back to summary |
|---|---|
| protected boolean containsOption(String name) Implements abstract org. Doc from org. Return whether the set of option arguments parsed from the command line contains an option with the given name.
| |
| getNonOptionArgs | back to summary |
|---|---|
| protected List Implements abstract org. Doc from org. Return the collection of non-option arguments parsed from the command line.
Never
| |
| getOptionValues | back to summary |
|---|---|
| protected List Implements abstract org. Doc from org. Return the collection of values associated with the command line option having the given name.
| |
| getPropertyNames | back to summary |
|---|---|
| public String[] getPropertyNames() Implements abstract org. Get the property names for the option arguments.
| |